James
James

Reputation: 557

remove jquery elements that do not have a class

Hi can any one help me get all elements in jquery that do not have a class.

I have a list and I want to get all of the that do not have a class and delete it

Here is the code I have so far

var listTableHeaders = $("ROI-List").find("th");
listTableHeaders.not(".sorting").remove();

I realized that there are other classes other than "sorting" as seen in this pic

enter image description here

I can just remove the elements that are not "sorting" or "sorting_disabled" but I am not sure if there are other classes so it would be more convenient to remove the th that do not have any class.

Thank you

Upvotes: 0

Views: 73

Answers (3)

Anthony Veach
Anthony Veach

Reputation: 320

I belive this will work for what you're trying to do:

$("ROI-List").find("th:not([class])").remove();

Upvotes: 1

frenchie
frenchie

Reputation: 51947

Something like this:

$("ROI-List").find("th").each(function () {

   if (!$(this).prop('class').length) {

      $(this).remove();
   }   
});

Upvotes: 1

Amit Joki
Amit Joki

Reputation: 59252

You can filter it

listTableHeaders.filter(function(){
   return !$(this).is('[class]');
}).remove();

Upvotes: 3

Related Questions