I have some HTML :
<div class="blah">
<div class="blah">
And I want to get all the divs with class 'blah'
var result = document.querySelector('.blah');
However the result is just the first element.
How do I get ALL elements?
Fiddle :
I have some HTML :
<div class="blah">
<div class="blah">
And I want to get all the divs with class 'blah'
var result = document.querySelector('.blah');
However the result is just the first element.
How do I get ALL elements?
Fiddle :
This is a hard one: querySelectorAll()
http://www.w3schools.com/jsref/met_document_queryselectorall.asp
Instead use document.querySelectorAll
which returns you a list.
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
You can do it with querySelectorALL
var result = document.querySelectorAll('.blah');
console.log(result.length)
<div class="blah">
<div class="blah">
Result are showed in the console.
With jQuery you can simplify it to:
$('.blah');