Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add <span> after <a>

Tags:

jquery

Hi I am using below jquery to add span after anchor tag.

Below is my code :

$(document).ready(function(){
   $("a.ext-or-pdf-link").append("<span class=test>test</span>");
});

But this is adding span inside <a> tag but i want to add after <a> in such a way <a ...> text </a><span class=test>test</span>.

Any Idea?

Thanks

like image 850
Vivek Dhiman Avatar asked Aug 18 '26 21:08

Vivek Dhiman


1 Answers

You need to use after()

$("a.ext-or-pdf-link").after("<span class=test>test</span>");

.append() adds the passed elements as the last child of the targeted element. So in your case the span will be added as the last child of the anchor instead of adding it as the next sibling

like image 110
Arun P Johny Avatar answered Aug 20 '26 12:08

Arun P Johny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!