Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery get only all html elements with ids

I have a div with many many html elements like other divs, trs, tds, tables etc

Is it possible to get all the elements which have an id? I know asking $("#test") will give me the specific element with this id

but is it possible to get find("#") or something like this?!

like image 206
stephan Avatar asked Jul 22 '09 08:07

stephan


People also ask

How do you select all elements with an ID?

The CSS id Selector 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.

How to get element with id in jQuery?

The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.

Which jQuery statement can you use to select all the elements on a webpage that has the CSS class name panel?

The . class selector selects all elements with the specific class. The class refers to the class attribute of an HTML element.


2 Answers

$('[id]') returns all elements that have id set

like image 181
RaYell Avatar answered Sep 18 '22 15:09

RaYell


You can use the following syntax to limit the results:

$('input[id*=test_id]').live('click', callbackFunc());

or

$('.elements_set[id*=test_id]').live('click', callbackFunc());

or in same manner

$('input[name*=test_id]').live('click', callbackFunc());

These are called Attribute Selectors

Reference links:

  • Attribute Contains Selector [name*="value"]
  • Attribute Contains Word Selector [name~="value"]
  • Attribute Ends With Selector [name$="value"]
  • Attribute Not Equal Selector [name!="value"]
  • Attribute Starts With Selector [name^="value"]
like image 25
Alex Rashkov Avatar answered Sep 20 '22 15:09

Alex Rashkov