开发者

how to simplify my code using jquery?

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&l开发者_开发技巧t;/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 think What you are looking for is the wrapinner function.

 $("a").wrapInner("<span></span>")

You can find a working example here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜