I would like to know how I can count the elements that exist with the same class in an HTML to be able to be with JQuery but with JavaScript also OK.
Thank you!
Example
div class="hola"
div class="hola"
div class="hola"
A script that says there are 3 elements with the class "hello".
What have I tried?
var divs = document.getElementsByClassName("orange");
var numDivs = divs.length;
var contadorNaranja = 0;
for(var i = 0; i < numDivs; i++){
if(divs[i].className == "orange")
contadorNaranja++;
}
var puntos1 = contadorNaranja;
document.getElementById("jugador1puntos").innerHTML = "Jugador1: "+puntos1;