Reputation: 27638
How would I write an event in jQuery so that if I click any of the links it'll delete not the divouter surrounding it, but the divouter before it?
<div class='divouter'>
<a href='#'>Link</a>
</div>
<div class='divouter'>
<a href='#'>Link</a>
</div>
<div class='divouter'>
<a href='#'>Link</a>
</div>
<div class='divouter'>
<a href='#'>Link</a>
</div>
Upvotes: 0
Views: 2698
Reputation: 7430
$('.divouter a').click(function(){
var prevParent = $(this).parent().prev();
if (prevParent.length) prevParent.remove();
});
Upvotes: 1
Reputation: 655489
Try this:
$(".divouter a").click(function() {
$(this).parent(".divouter").prev(".divouter:last").remove();
});
Upvotes: 1