admin管理员组文章数量:1405618
I want append <span></span>
tag in my every <a>
tag:
now:
<a href=#>aaa</a>
<a href=#>bbb</a>
<a href=#>ccc</a>
I want:
<a href=#><span>aaa</span></a>
<a href=#><span>bbb</span></a>
<a href=#><span>ccc</span></a>
now ,i using below codes to implement it:
$(function(){
var buttons = $("a");
var text=buttons.text();
buttons.text("");
buttons.prepend("<span>"+text+"</span>");
});
I think this codes is not good,how to simplify it?
thanks :)
I want append <span></span>
tag in my every <a>
tag:
now:
<a href=#>aaa</a>
<a href=#>bbb</a>
<a href=#>ccc</a>
I want:
<a href=#><span>aaa</span></a>
<a href=#><span>bbb</span></a>
<a href=#><span>ccc</span></a>
now ,i using below codes to implement it:
$(function(){
var buttons = $("a");
var text=buttons.text();
buttons.text("");
buttons.prepend("<span>"+text+"</span>");
});
I think this codes is not good,how to simplify it?
thanks :)
Share Improve this question asked Dec 30, 2010 at 5:20 KoerrKoerr 15.8k29 gold badges80 silver badges109 bronze badges1 Answer
Reset to default 16I think What you are looking for is the wrapinner function.
$("a").wrapInner("<span></span>")
You can find a working example here.
本文标签: javascripthow to simplify my code using jqueryStack Overflow
版权声明:本文标题:javascript - how to simplify my code using jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744909547a2631829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论