How to add span tag within anchor, changing it from
<a href="somewhere.html">Here is the link to somewhere.</a>
to this with jquery
<a href="somewhere.html">
<span>Here is the span content.</span>
Here is the link to somewhere.
</a>
Try this:
$('a').each(function() {
$(this).prepend('<span>This is the span content</span>');
});
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(...
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