Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

querySelectorAll - get ALL tags that have an attribute set?

For example, I need to have a list of all tags that have id attribute set (it could be any other attribute, id is just an example).

like image 892
rsk82 Avatar asked Jan 01 '12 17:01

rsk82


People also ask

How do you get all elements with a data attribute?

To get all DOM elements by a data attribute, use the querySelectorAll method, e.g. document. querySelectorAll('[data-id]') . The querySelectorAll method returns a NodeList containing the elements that match the specified selector.

What does the querySelectorAll () method do?

Document.querySelectorAll() The Document method querySelectorAll() returns a static (not live) NodeList representing a list of the document's elements that match the specified group of selectors.

How do I get attributes from querySelector?

How it works: First, select the link element with the id js using the querySelector() method. Second, get the target attribute of the link by calling the getAttribute() of the selected link element. Third, show the value of the target on the Console window.

How do I use querySelector with data attribute?

Use the querySelector method to get an element by data attribute, e.g. document. querySelector('[data-id="box1"]') . The querySelector method returns the first element that matches the provided selector or null if no element matches the selector in the document.


1 Answers

Try this:

document.querySelectorAll('[id]')
like image 173
Sergio Tulentsev Avatar answered Nov 15 '22 08:11

Sergio Tulentsev