I need help in adding an element at a particular location in the page body.
Here is my page code.
<div id="div1>
<label id="label1"></label>
<input type="text1"></input>
<!-- Insert button here -->
<span id="span1"></span>
</div>
I want to add a button at the location where I have put a comment above using jQuery. If the page syntax is fixed, is there a way I can add an element as a third child of the parent div? I do not want to put placeholders and do a string replace.
Thanks.
$('#div1').children(':eq(1)').after('<button/>');
jsFiddle example.
button.insertAfter($('#div1').children().eq(1));
This will insert the button
after the 2nd child of #div1
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