Just do a document.write() and bypass jQuery.

if (thehour >= 18)
   document.write(...);

Since you're just checking time, you don't need to wait for the DOM to be
ready or any of that sort of thing.

-- dz


On Thu, Jun 4, 2009 at 12:23 PM, jez <j...@h4x3d.com> wrote:

>
> Hello,
> I am almost certain one of you guys will have a super quick solution
> to this, but I just can't get it and it is doing my head in:
>
> I have this piece of code which basically checks on client-side what
> time of the day it is.
> This information should be used to "use" different stylesheets based
> on the time, e.g.
> >=18 will be night.css
> >=15 will be afternoon.css, etc.
>
> however I cannot get to write this piece of html (e.g. <link
> rel="stylesheet" href="night.css" type="text/css" media="screen"
> title="night" charset="utf-8" />) by means of jquery.
>
> I was able to set the class of <body> to either night, afternoon,
> noon, etc, but I would rather like a solution where the time is
> translated into night.css, afternoon.css, etc.
>
> --- see code below ---
>
> //date
>  datetoday = new Date();
>  timenow = datetoday.getTime();
>  datetoday.setTime(timenow);
>  thehour = datetoday.getHours();
>
>  if (thehour >= 18)
>    $('body').addClass('evening');
>  else if (thehour >= 15)
>    $('body').addClass('afternoon');
>  else if (thehour >= 12)
>    $('body').addClass('noon');
>  else if (thehour >= 7)
>    $('body').addClass('morning');
>  else if (thehour >= 0)
>    $('body').addClass('night');
>  else
>    $('body').addClass('general');
> //end
>
> Many thanks in advance for any suggestions and replies!
> Any pointers or brain teasers welcome!
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to