Reputation: 22323
I want to search first div after delete
class inside a table. if exist than delete that div.I have sample in
jsfiddle what I am try.Suggest a correct way to do this.Thanks
Upvotes: 0
Views: 298
Reputation: 9968
$('table tr td').live("click", function() {
$('table tr td > div').remove();
});
Upvotes: 0
Reputation: 9902
try this demo http://jsfiddle.net/6YpBd/4/
It just remove the immediate div for the .delete class
If we use siblings() method it removes all the div elements before and after .delete class
$('.delete').on("click", function() {
$(this).next('div').remove();
});
Upvotes: 0
Reputation: 3535
For all jquery versions..
$('.delete').delegate('',"click", function() {
$(this).siblings('div').remove();
});
Upvotes: 1
Reputation: 12190
DEMO- http://jsfiddle.net/XtN87/
$('.delete').live("click", function() {
$(this).siblings('div').remove();
});
Upvotes: 0
Reputation: 145408
If you want to remove the sibling div
element you can use siblings
method:
$(".delete").live("click", function() {
$(this).siblings('div').remove();
});
DEMO: http://jsfiddle.net/6YpBd/2/
Consider using on
method instead of live
which is deprecated:
$("table").on("click", ".delete", function() { ... });
Upvotes: 0