dimanche 29 mars 2015

Access nested html elements and set their css

The content of an html file is given below and i want to be able to access each of the divs with the id="z" and set them to a different background color using a loop in a js file.



<div id="x">
<div class="y">
<div id="z">
</div>
</div>
<div class="y">
<div id="z">
</div>
</div>
<div class="y">
<div id="z">
</div>
</div>
.
.
</div>


The loop



for (i = 0; i < cnt; i++) {
$( " ? ? ? " ).css( "background", color[i] );
}

Aucun commentaire:

Enregistrer un commentaire