Reputation: 2361
<div class="test mypro demo-class" id="test-1">test</div>
<div class="test mypro demo-class" id="test-3">test</div>
<div class="test mypro demo-class" id="test-4">test 2 no demo class</div>
<div class="test mypro" id="test-2">test 2 no demo class</div>
in the above code i want to remove the div with id#test-2 with an additional condition check of div should not have .demo-class i tried this
$("#test-2 div:not(.demo-class)").remove();
please help thanks in advance
Upvotes: 1
Views: 1688
Reputation: 38102
Currently, you've two elements with id
test-2, chane it to class:
<div class="test mypro demo-class test-2">test 2 no demo class</div>
<div class="test mypro test-2">test 2 no demo class</div>
and then use:
$(".test-2:not(.demo-class)").remove()
Upvotes: 0
Reputation: 35963
try this:
$("#test-2").not('.demo-class').remove();
but I reccomend you to use unique ID use classes instead!
Upvotes: 1