在jquery中的锚点中添加span标记

boc*_*cca 4 jquery

如何在锚点中添加span标记,从中更改它

<a href="somewhere.html">Here is the link to somewhere.</a>
Run Code Online (Sandbox Code Playgroud)

这与jquery

<a href="somewhere.html">
<span>Here is the span content.</span>
Here is the link to somewhere.
</a>
Run Code Online (Sandbox Code Playgroud)

Tat*_*nen 5

试试这个:

$('a').each(function() {
     $(this).prepend('<span>This is the span content</span>');
});
Run Code Online (Sandbox Code Playgroud)

这会将span标记添加到a页面上每个元素的开头.如果要将修改限制为某些特定元素,请向它们添加一个类,并使用类似的方法调用它们$('a.myclass').each(...