Reputation: 9365
I've my mark up as
<div id="wrap">
<div class="clickhere"></div>
<div class="clickhere"></div>
<div class="clickhere"></div>
<div class="clickhere"></div>
<div class="clickhere"></div>
</div>
Now, I want to add another <div class="clickhere"></div>
just after the div clicked using jQuery. I thought of .append()
or .prepend()
but it only adds at the last or the first of the parent element (if applied at the parent element).
$('.clickhere').click(function(){
// add <div class="clickhere"></div> just below $(this)
})
Upvotes: 0
Views: 1536
Reputation: 147383
And in something approaching POJS:
> $('.clickhere').click(function(){
var div = document.createElement('div');
div.className = 'clickhere';
this.parentNode.insertBefore(div, this.nextSibling);
> just below $(this) })
Upvotes: 0
Reputation: 1145
You have .insertAfter()
for that :)
$('<div class="clickhere"></div>').insertAfter(this);
Upvotes: 5