Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting all elements that do not have an "id" attribute?

How can I select all the elements on a page that do not have an "id" attribute? What is the selector for this in jQuery?

like image 482
ward87 Avatar asked Mar 06 '12 13:03

ward87


People also ask

How do you select all elements with an ID?

The id selector uses the id attribute of an HTML element to select a specific element. The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.

Should all elements have an ID?

You do not need to put ID attribute if it is not required, and you can always add ID attribute whenever required. Keeping only required elements in html will make it easy to read, clean, low on size and hence improves performance and speed.

Can a element have ID?

The HTML id attribute is used to specify a unique id for an HTML element. You cannot have more than one element with the same id in an HTML document.

How do you select an element without a class?

The :not CSS pseudo-class can be used to select elements that do not contain a specific class, id, attribute etc.


2 Answers

Negative selector :not([id]) should work. See:

  • http://api.jquery.com/not-selector/
  • http://api.jquery.com/has-attribute-selector/
like image 162
Marat Tanalin Avatar answered Sep 22 '22 16:09

Marat Tanalin


You can use $(':not([id])'). That should work fine.

like image 38
Can Yener Avatar answered Sep 19 '22 16:09

Can Yener