Reputation: 2655
I have a question regarding the GetElementsByTagName, i would like to retrieve all elements which are TD but also have class name "MyClass" and which do not have an attribute height.
I do the following:
document.getElementsByTagName("TD")
and it works. When i do
document.getElementsByTagName("TD.MyClass:not[height]")
it doesn't work
How do I make it possible withouth using JQuery or can i retrieve first all TD's and then apply some filter on the set of td's?
Any help?
Upvotes: 3
Views: 17542
Reputation: 128791
This is something you'd use document.querySelectorAll()
for. It's worth noting that you'd need to use brackets around that :not[height]
, too, otherwise your selector isn't valid:
document.querySelectorAll("TD.MyClass:not([height])");
Upvotes: 7
Reputation: 3627
you can use document.querySelectorAll
which returns collection of html nodes that apply to given selector
document.querySelectorAll('td.myClass'); // will return array of all tds with given class
Upvotes: 3