+ 3
Is there Any Possibity Of Selecting All Elements With Id Attribute in Js
6 ответов
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
+ 4
//use
document.getElementsByTagName('*')
or
//Give a elements a same id
https://stackoverflow.com/questions/10770172/select-all-ids-or-classs-with-getelementby
+ 4
I did some experiments and found this solution
window.onload = () => {
document.querySelectorAll("td").forEach(x=>{
if(x.hasAttribute("id")) {
//TODO
}
});
}
+ 2
What about using class?
document.getElementsByClassname
+ 1
Not All, I want To select All " td " elements that Have id Attribute
+ 1
You can, instead of using id, use class by using
document.getElementByClassname