Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add span tag within anchor in jquery

Tags:

jquery

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>
like image 698
bocca Avatar asked Jan 06 '10 14:01

bocca


1 Answers

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(...

like image 160
Tatu Ulmanen Avatar answered Oct 23 '22 17:10

Tatu Ulmanen