lundi 18 juillet 2016

how to change background color of multiple td elements using jquery

I'm unable to change the background color of multiple td elements in a table using jquery.

HTML code :

<td id="trueValue">/com/website/seo/</td>

<td id="trueValue">/com/website/seo/</td>

<td id="falseValue">/com/website/seo/</td>

<td id="falseValue">/com/website/seo/</td>

Jquery code :

 $("td").each(function() {
 var i = $(this).attr("id");
 if (i == "trueValue") {
    $(i).css("background-color", "green");
    }
 });

The above jquery is doing nothing. Can someone correct my code please?

Many Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire