samedi 11 juin 2016

Class attribute set but not displayed in some cases


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?

enter image description here enter image description here

enter image description here enter image description here


Aucun commentaire:

Enregistrer un commentaire