Cris
Cris

Reputation: 4044

How to select all elements that don't have a class or id?

If I want to select the elements that don't have a class (but may have an ID), the following

$(".entry-container ul:not([class])").addClass("list type-1"); works fine.

If I want to select the elements that don't have an ID (but may have a class) the following

$(".entry-container ul:not([id])").addClass("list type-1"); works fine.

But what if I want to select all the elements that don't have a class AND and an ID?

Upvotes: 2

Views: 409

Answers (3)

Ram
Ram

Reputation: 144659

$(".entry-container ul").not("[id][class]").addClass("list type-1"); 

Using .filter() method:

$(".entry-container ul").filter(function() {
   return this.id === '' && this.className === '';
});

Upvotes: 3

Harold Sota
Harold Sota

Reputation: 7566

see these: http://www.nicksays.co.uk/css-boolean-selectors/

$(".entry-container ul:not([class]) .entry-container ul:not([id])").addClass("list type-1");

Upvotes: 1

PSL
PSL

Reputation: 123739

Try

$(".entry-container ul:not([id],[class])").addClass("list type-1");

Upvotes: 1

Related Questions