Trying to convert some jQuery to javascript. Was using this for jQuery:
var list = $('.list li'),
listLength = list.length;
Now I’m trying it with JS, but it doesn’t seem to work:
var list = document.querySelector(".list"),
listLi = list.getElementsByTagName("li"),
listLength = listLi.length;
Any ideas?
Your code should already work. But you can also use
document.querySelectorAll()to perform a selector match which is cleaner than the two separate calls: