Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all elements with an 'id' attribute on the DOM [duplicate]

Simple. I want to traverse the DOM and find all elements that have an id attribute. Can someone help me with a js and/or jquery script

like image 987
Jay Avatar asked Sep 07 '25 07:09

Jay


2 Answers

You can query all the elements with an id attribute by using the following jQuery selector:

$("[id]")

You can also just use plain JavaScript using querySelectorAll:

document.querySelectorAll("[id]")

If you want to find non-empty id attributes, use this selector instead:

'[id]:not([id=""])'
like image 187
Alexis King Avatar answered Sep 09 '25 15:09

Alexis King


Simple attribute selector

$('[id]');

Reference : Has Attribute Selector [name]

like image 28
charlietfl Avatar answered Sep 09 '25 16:09

charlietfl