在jquery中的锚点内添加span标签 [英] add span tag within anchor in jquery
本文介绍了在jquery中的锚点内添加span标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在锚点中添加跨度标签,将其从更改为
How to add span tag within anchor, changing it from
<a href="somewhere.html">Here is the link to somewhere.</a>
使用jquery对此
<a href="somewhere.html">
<span>Here is the span content.</span>
Here is the link to somewhere.
</a>
推荐答案
尝试一下:
$('a').each(function() {
$(this).prepend('<span>This is the span content</span>');
});
这将在页面上每个a
元素的开头添加一个span标记.如果要限制对某些特定元素的修改,请向它们添加一个类,并使用类似$('a.myclass').each(...
This will add a span tag to the start of each and every a
element on the page. If you want to restrict the modifying to some specific elements, add a class to them and call them with something like $('a.myclass').each(...
这篇关于在jquery中的锚点内添加span标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文