2
I have a div of id=colors and inside I have other Ivs with several classes
<div id="cores">
<div class="azul">conteúdo</div>
<div class="amarelo">conteúdo</div>
<div class="verde">conteúdo</div>
<div class="azul">conteúdo </div>
</div>
I would like to set up a function that would determine how many Ivs with defined class and how many classes there are of each element.
I don’t know if I made myself clear.
Part one solution (Make an array with only class names). I found a solution with find:
var array_cores = [];
$("#cores").find('div').each(function(){
var classe = $(this).attr("class");
arrayObjetos.push({classe});
});
console.log(array_cores);
Generates a result like this;
var array_cores = ["azul", "amarelo", "verde", "azul"];
Now I must count the repetitions
The
id
should be unique on each page.– MagicHat
Sorry, I was wrong to write here, are as classes, I will arrange
– Alê Moraes
A function that assembles an array of class names and the repetition quantities of that class
– Alê Moraes
Ahh I get it....
– Sam