<div>
<div class="one">One</div>
<div class="two">Two</div>
<div class="three">Three</div>
<div class="four">Four</div>
<div class="five">Five</div>
</div>
I need to add a div between div Three and Four, but I can't use any sort of targeting on the parent div (only the divs inside it).
jQuery('.four').parent().prepend('<div class="addme">Add Me!</div>');
This as you probably know adds it to the top, above div One. Without the ".parent()" it adds the div inside of div Four, before the content. Same difference for ".append()".
Anyone got a solution?
You can use .before()
or .after()
like this:
jQuery('.four').before('<div class="addme">Add Me!</div>');
//or...
jQuery('.three').after('<div class="addme">Add Me!</div>');
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