Reputation: 21877
I have the following DOM structure:
<div class="city">
<div class="a">Delete</div>
<div class="b">Selected</div>
<div class="c">Delete</div>
</div>
How do you save city and div class b, but delete div class a and c if you know that the user has selected "b" (you know this using logs your console.log(variable))
Basically what JQuery method would you use to do this and how?
Upvotes: 2
Views: 74
Reputation: 29831
$('.city').find('.a, .c').remove();
Or
$('.city div:not(.b)').remove();
var selectedClass = 'b';
$('.city div').not('.' + selectedClass).remove();
Upvotes: 1
Reputation: 268354
Given your structure, I'd probably use the following:
$(".b").siblings().remove();
See it in action: http://jsbin.com/akuno3/edit
Upvotes: 2
Reputation: 37136
Basically I would do:
$(".b").click(function () {
$(".a,.c").remove();
});
Upvotes: 0
Reputation: 82913
Try this:
$("div.city div.b").click(function() {
$(this).siblings().remove()
})
Upvotes: 0