I am creating dynamically an HTML table in JavaScript, and when a condition is true, I set one class attribute to the tr
element:
var tablaindice = result.tablaindice;
for (var key in tablaindice)
{
var trautor = document.createElement("tr");
var tdart = document.createElement("td");
tdart.innerHTML = key;
var tdcitas = document.createElement("td");
tdcitas.innerHTML = tablaindice[key];
if(key == result.indiceh)
{
trautor.setAttribute("class", "indiceh");
}
trautor.appendChild(tdart);
trautor.appendChild(tdcitas);
tbody.appendChild(trautor);
}
And this is the CSS code:
.indiceh{
background-color: lightblue;
}
The class attribute is always set to the right element, but in some cases the blue background is displayed and in others it doesn't. Why is this happening?
Aucun commentaire:
Enregistrer un commentaire