I wanted to get a list of DOM elements by class name and tag name in JavaScript, not using jQuery.
For example I need to get all <ul>
elements with class .active
var elements = document.getElementsByTagName("ul");
var activeElements = document.getElementsByClassName('active')
What is the fastest and best way to do this in JavaScript.
No external libraries like jQuery or cheerio
I wanted to get a list of DOM elements by class name and tag name in JavaScript, not using jQuery.
For example I need to get all <ul>
elements with class .active
var elements = document.getElementsByTagName("ul");
var activeElements = document.getElementsByClassName('active')
What is the fastest and best way to do this in JavaScript.
No external libraries like jQuery or cheerio
Share Improve this question edited Nov 22, 2017 at 3:16 svnm asked Aug 25, 2015 at 1:21 svnmsvnm 24.3k23 gold badges94 silver badges109 bronze badges 2 |1 Answer
Reset to default 18document.querySelectorAll('ul.active')
document.querySelectorAll()
. – Pointy Commented Aug 25, 2015 at 1:22