Reputation: 883
(in vanilla JavaScript) I was wondering if the was an easy way to do something like
x = document.getElementsByTagName('span') && getElementsByClassName('null');
To return all 'span' elements that have the class name 'null'?
I thought it might have been something like:
x = document.getElementsByTagName('span');
x = x.getElementsByClassName('null');
// or
x = document.getElementsByTagName('span').getElementsByClassName('null');
But that didn't seem to work out.
Is this possible or will I have to iterate through x popping anything that returns false for .class='null'?
Thanks.
Upvotes: 13
Views: 22723
Reputation: 887453
The DOM does not provide any APIs for filtering NodeLists.
Instead, you can use CSS selectors:
var x = document.querySelectorAll('span.null');
Upvotes: 23