8

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 :)

1 Answer 1

16

I think What you are looking for is the wrapinner function.

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

You can find a working example here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.