<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Japh &#187; Cascading Stylesheets</title>
	<atom:link href="http://japh.com.au/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://japh.com.au</link>
	<description>Web developer, technologist, innovator. I love the internet.</description>
	<lastBuildDate>Tue, 13 Jul 2010 10:48:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Time-sensitive CSS</title>
		<link>http://japh.com.au/html/time-sensitive-css/</link>
		<comments>http://japh.com.au/html/time-sensitive-css/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 09:18:28 +0000</pubDate>
		<dc:creator>Japh</dc:creator>
				<category><![CDATA[Cascading Stylesheets]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://japh.com.au/?p=115</guid>
		<description><![CDATA[Have you ever wanted to load a specific stylesheet depending on what time it is?  It is actually very easy to do!
View Demo
I&#8217;m using jQuery in this just because it makes it look a little simpler, it&#8217;s not much more complex to do without jQuery&#8230; but let&#8217;s face it, you&#8217;re probably already using jQuery [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Have you ever wanted to load a specific stylesheet depending on what time it is?  It is actually very easy to do!</p>
<p><a href="/demos/115/">View Demo</a></p>
<p>I&#8217;m using jQuery in this just because it makes it look a little simpler, it&#8217;s not much more complex to do without jQuery&#8230; but let&#8217;s face it, you&#8217;re probably already using jQuery anyway, so why not  <img src='http://japh.com.au/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Make yourself a new file to put your javascript into, I&#8217;ve called mine &#8220;script.js&#8221;.  Include the new javascript file by putting this line in your HTML &lt;head&gt;&lt;/head&gt; section with the following line:</p>

<div class="wp_codebox"><table><tr id="p1153"><td class="code" id="p115code3"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;script.js&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>

<p>Now open your &#8220;script.js&#8221; file, and put the following lump of code into it:</p>

<div class="wp_codebox"><table><tr id="p1154"><td class="code" id="p115code4"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// This line depends on jQuery, and tells the browser to kick off this stuff once</span>
<span style="color: #006600; font-style: italic;">// everything's fully loaded</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// These two lines make set a Date variable with the current date and time</span>
    <span style="color: #003366; font-weight: bold;">var</span> currentDate <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> currentHour <span style="color: #339933;">=</span> currentDate.<span style="color: #660066;">getHours</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Here we're creating a new &lt;link /&gt; to insert in the &lt;head&gt;&lt;/head&gt;</span>
    <span style="color: #003366; font-weight: bold;">var</span> newCSS <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    newCSS.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'text/css'</span><span style="color: #339933;">;</span>
    newCSS.<span style="color: #660066;">rel</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'stylesheet'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// This is where you can determine when to use which stylesheet.</span>
    <span style="color: #006600; font-style: italic;">// If the current hour is before 9am or 8pm (or later), use &quot;night.css&quot;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>currentHour <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">9</span> <span style="color: #339933;">||</span> currentHour <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        newCSS.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'css/night.css'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #006600; font-style: italic;">// Otherwise, use &quot;day.css&quot;</span>
    <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        newCSS.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'css/day.css'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #006600; font-style: italic;">// This line actually does the deed, and attaches the selected stylesheet</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;head&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>newCSS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// This line isn't necessary, it's just showing the actual time in the demo.</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.satellite&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>currentDate.<span style="color: #660066;">toTimeString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Read the commenting to understand what&#8217;s actually going on there, but that should do it!  Easier than you thought, I bet  <img src='http://japh.com.au/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If you have any questions or suggestions, leave a comment!</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://japh.com.au/html/time-sensitive-css/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
