4b0
4b0

Reputation: 22323

Search and Delete first div inside a table in jquery

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

My sample

Upvotes: 0

Views: 298

Answers (5)

Waqar Alamgir
Waqar Alamgir

Reputation: 9968

$('table tr td').live("click", function() {
$('table tr td > div').remove();
});

Upvotes: 0

Valli69
Valli69

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

Priyank Patel
Priyank Patel

Reputation: 3535

For all jquery versions..

$('.delete').delegate('',"click", function() {
    $(this).siblings('div').remove();
});​

Upvotes: 1

Dipak
Dipak

Reputation: 12190

DEMO- http://jsfiddle.net/XtN87/

$('.delete').live("click", function() {
    $(this).siblings('div').remove();
});

Upvotes: 0

VisioN
VisioN

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

Related Questions