+ 3

Is there Any Possibity Of Selecting All Elements With Id Attribute in Js

16th Feb 2019, 4:11 PM
Naqib Ali
Naqib Ali - avatar
7 odpowiedzi
0
CSS [attribute] Selector The [attribute] selector is used to select elements with a specified attribute. source: https://www.w3schools.com/css/css_attribute_selectors.asp https://www.w3schools.com/cssref/trysel.asp
16th Feb 2019, 7:18 PM
ODLNT
ODLNT - avatar
+ 4
//use document.getElementsByTagName('*') or //Give a elements a same id https://stackoverflow.com/questions/10770172/select-all-ids-or-classs-with-getelementby
16th Feb 2019, 4:17 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 4
I did some experiments and found this solution window.onload = () => { document.querySelectorAll("td").forEach(x=>{ if(x.hasAttribute("id")) { //TODO } }); }
16th Feb 2019, 4:21 PM
Seniru
Seniru - avatar
+ 2
What about using class? document.getElementsByClassname
16th Feb 2019, 4:25 PM
Maneren
Maneren - avatar
+ 1
Not All, I want To select All " td " elements that Have id Attribute
16th Feb 2019, 4:17 PM
Naqib Ali
Naqib Ali - avatar
+ 1
You can, instead of using id, use class by using document.getElementByClassname
16th Feb 2019, 4:34 PM
Bebida Roja
Bebida Roja - avatar