Karthick Kumar
Karthick Kumar

Reputation: 2361

jquery conditional selectors

<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

Answers (2)

Felix
Felix

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()

Demo

Upvotes: 0

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35963

try this:

$("#test-2").not('.demo-class').remove();

but I reccomend you to use unique ID use classes instead!

http://api.jquery.com/not/

Upvotes: 1

Related Questions