How in jQuery would I add a button directly after an anchor tag? For example, my HTML looks like:
<div style="border-style: solid; border-width: thin; padding: 2px;">
<center>
<a target="_blank" href="http://www.mydomain.com/">MyDomain.com</a>
<b>My Hypertext Link</b>
<br/>
Options:
<a class="theAClass" href="#">Insert button after this anchor</a>
</center>
</div>
I want to add a button just after the anchor (class="theAClass") but before the "center" tag so the button is centered on the page.
$('.theAClass').after('<button>...</button>')
Should do the trick. That will append the html you specify immediately after the tag.
//Add button after every theAclass link
$('a.theAClass').after('<button type="button">Click Me!</button>');
//Add button after only the first theAclass link
$('a.theAClass:first').after('<button type="button">Click Me!</button>');
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