Create a small script
that runs around div
, check if they share one of the # id that is in the # array and if so, add a div
inside.
I want to make that if you do not follow the rule the div
disappears but if I use else{ $(this).remove()}
it erases all div
.
When I use else{ $(this).addClass()
applies the class to those who meet the 1 condition, not those who do not comply.
Do you know why it can be?
var arreglo = ["A", "B", "c", "d","E","f","g","H"];
$(".sup > div").each(function(index){
console.log("comprobación "+index)
for(i=0; i< arreglo.length; i++ ){
var id_ = $(this).attr("id") //obtiene la #id del div
if(arreglo[i] === id_){//compara las #id si son iguales
console.log(arreglo[i]+" = "+id_+" BINGO")//lo declara en la consola
$(this).append("<div class='prueba'/>");//dibuja un div dentro
} else if(arreglo[i] !== id_){
console.log(arreglo[i]+" = "+id_+" NO")
$(this).toggleClass("class")
}
}//for2
}/*function*/)