How To Get Only Specific Tags Of Elementsbyclassname?
Solution 1:
If you can, use querySelectorAll:
var elements = document.querySelectorAll("span.dates");
Otherwise, you can use tagName to filter down your existing elements:
var elements = document.getElementsByClassName("dates");
for(var i=elements.length; i--;) {
if(elements[i].tagName.toLowerCase() != "span") continue;
// Do work
}
Solution 2:
In modern browsers you may use the CSS selector with querySelectorAll
:
var elements = document.querySelectorAll('div.dates, span.dates');
It is supported by the following browsers:
- Chrome - 1
- Firefox (Gecko) - 3.5 (1.9.1)
- Internet Explorer - 9 and 8 (CSS2 selectors only)
- Opera - 10
- Safari (WebKit) - 3.2 (525.3)
Post a Comment for "How To Get Only Specific Tags Of Elementsbyclassname?"