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 :)
jQuery is a JavaScript library that helps to simplify and standardize interactions between JavaScript code and HTML elements.
jQuery promotes simplicityWith simple syntax and open coding standards, developers can shorten the time it takes to deploy an application or site. In addition, developers don't have to be experts in programming or Web design to create great styles for their sites.
The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s). Basic syntax is: $(selector).action() A $ sign to define/access jQuery. A (selector) to "query (or find)" HTML elements.
I think What you are looking for is the wrapinner function.
$("a").wrapInner("<span></span>")
You can find a working example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With