Reputation: 135
I have two divs:
<div class="dialog large"></div>
and
<div class="dialog"></div>
I have to remove the one with the class "dialog" but keep the one with "dialog large".
If I do $('dialog').remove();
they are both removed.
Can anyone help me with this?
Upvotes: 2
Views: 483
Reputation: 7169
if you want to remove DIVs where the class is exactly "dialog", try:
$('div[class="dialog"]').remove();
Upvotes: 0
Reputation: 87073
$('div.dialog:not(.large)').remove();
div.dialog
will select div
with class=dialog
(in this case both div will select). But
div.dialog:not(.large)
will exclude those div
with class
large
and remove them.
Upvotes: 4
Reputation: 94101
There are many many ways to do it. You could also use filter()
as an alternative maybe suitable for other more complicated cases.
$('div.dialog').filter(function(){ return !$(this).is('.large') })
Upvotes: 0
Reputation: 167172
Use this:
$("div.dialog").not('.large').remove();
Fiddle here...
Upvotes: 0