Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery empty but exclude a certain element

I try to empty() a div but exclude a specific selector.

What I've tried so far:

$('.modal').find('.close').nextAll().empty();
$('.modal').find(':not(.close)').empty();
$('.modal').not('.close').empty();
$('.modal:not(.close)').empty();

HTML:

<div class="modal">
  <a href="#" class="close">Close</a>
  ...I've the need to be removed...
</div>
like image 561
yckart Avatar asked Oct 18 '25 19:10

yckart


1 Answers

Could be done like this:

http://fiddle.jshell.net/KLh4E/11/

$(".modal").contents().filter(function(){
    return !$(this).is('.close');
}).remove();
like image 183
A. Wolff Avatar answered Oct 20 '25 09:10

A. Wolff