css - Jquery - coloring the background of all id -


in html file below, jquery not coloring background of id="0". jquery coloring first id. how can make id="0" colored jquery?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <table>     <tr>         <td align="center" style="padding-top: 15px;" id="0">0</td>            </tr>     <tr>         <td align="center" style="padding-top: 15px;" id="0">0</td>     </tr> </table> <script>     $(document).ready(function(){         $("td#0").css("background-color", "rgba(201, 221, 237, 0.99)");     }); </script> 

an id has unique work properly. when try find elements duplicate id, browser give 1 of them.

you should use different way of finding elements, example adding class elements, or putting id on table , use select cells in it.

for completeness, it's still possible find elements duplicate id, have treat attribute:

$("td[id='0']").css("background-color", "rgba(201, 221, 237, 0.99)"); 

you should of course use if can't change html code, , id way select elements.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -