javascript - How to you change the text color of the current date using the getDate method? -


the output doesn't change color of current date. when add in sample alert statement within case statement, alert works. when remove , add in style.color = "red", current date doesn't turn red. why that?

<head>  <script>  switch (new date().getday()) {     case 0:          document.getelementbyid("sun").style.color = "red";         break;     case 1:         document.getelementbyid("mon").style.color = "red";         break;     case 2:         document.getelementbyid("tues").style.color = "red";         break;     case 3:         document.getelementbyid("wed").style.color = "red";         break;     case 4:         document.getelementbyid("thur").style.color = "red";         break;     case 5:         document.getelementbyid("fri").style.color = "red";         break;     case  6:         document.getelementbyid("sat").style.color = "red";         break; }  </script>     </head>  <body>     <table>         <tr>             <td><p id="sun">sun</p></td>             <td><p id="mon">mon</p></td>             <td><p id="tue">tue</p></td>             <td><p id="wed">wed</p></td>             <td><p id="thur">thur</p></td>             <td><p id="fri">fri</p></td>             <td><p id="sat">sat</p></td>                                 </tr>     </table>                     </body> </html> 

move script tag below body section, gets executed first when elements have not been rendered in dom , hence not colours.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

android - Go back to previous fragment -