Change CSS based on time of the day


/ Published in: JavaScript
Save to your folder(s)

Use this in the `` of your HTML files.


Copy this code and paste it in your HTML
  1. <link rel="stylesheet" type="text/css" media="screen, projection" href="screen.css" />
  2. <script type="text/javascript">
  3. <!--
  4. var d = new Date();
  5. var sunrise = 6; // 6 AM
  6. var sunset = 18; // 6 PM
  7. var currentHour = parseInt(d.getHours());
  8. if(currentHour >= sunset || currentHour <= sunrise){
  9. document.write('<link rel="stylesheet" href="dark.css" media="screen, projection" /' + '>');
  10. }
  11. // -->
  12. </script>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.