<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>The House of AnimeJB &#187; CSS</title>
	<atom:link href="http://www.animejb.net/category/tips-tricks/css/feed" rel="self" type="application/rss+xml" />
	<link>http://www.animejb.net</link>
	<description>The House of AnimeJB</description>
	<pubDate>Mon, 15 Dec 2008 18:55:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<!-- podcast_generator="podPress/8.8" -->
		<copyright>&#xA9; </copyright>
		<managingEditor>cal@animejb.net ()</managingEditor>
		<webMaster>cal@animejb.net()</webMaster>
		<category></category>
		<ttl>1440</ttl>
		<itunes:keywords></itunes:keywords>
		<itunes:subtitle></itunes:subtitle>
		<itunes:summary>The House of AnimeJB</itunes:summary>
		<itunes:author></itunes:author>
		<itunes:category text="Society &amp; Culture"/>
		<itunes:owner>
			<itunes:name></itunes:name>
			<itunes:email>cal@animejb.net</itunes:email>
		</itunes:owner>
		<itunes:block>No</itunes:block>
		<itunes:explicit>no</itunes:explicit>
		<itunes:image href="http://www.animejb.net/wp-content/plugins/podpress/images/powered_by_podpress_large.jpg" />
		<image>
			<url>http://www.animejb.net/wp-content/plugins/podpress/images/powered_by_podpress.jpg</url>
			<title>The House of AnimeJB</title>
			<link>http://www.animejb.net</link>
			<width>144</width>
			<height>144</height>
		</image>
		<item>
		<title>Dynamic Style Sheets</title>
		<link>http://www.animejb.net/2006/06/29/dynamic-style-sheets</link>
		<comments>http://www.animejb.net/2006/06/29/dynamic-style-sheets#comments</comments>
		<pubDate>Thu, 29 Jun 2006 16:29:44 +0000</pubDate>
		<dc:creator>Calophi</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.animejb.net/2006/06/29/dynamic-style-sheets/</guid>
		<description><![CDATA[This isn&#8217;t about rotating through alternate stylesheets or importing them, or even changing an inline style on an element through Javascript.  Oh no.  This is about creating an actually stylesheet element ON THE FLY.
The reason for this is because for a bit I was just trying to create a long string with the [...]]]></description>
			<content:encoded><![CDATA[<p>This isn&#8217;t about rotating through alternate stylesheets or importing them, or even changing an inline style on an element through Javascript.  Oh no.  This is about creating an actually stylesheet element ON THE FLY.</p>
<p>The reason for this is because for a bit I was just trying to create a long string with the style tags and rules inside it, and then just pop it in the innerHTML of the body.  (Hey, I&#8217;m no Guru, I have a lot to learn!) Needless to say, this caused a few issues.</p>
<p><span id="more-45"></span></p>
<p>At first I tried to use <a href="http://www.howtocreate.co.uk/tutorials/javascript/domstylesheets">DOM Stylesheets</a> to serve my purposes, but I soon found that although they work in Mozilla and IE (though IE works funny and has different functions to use), the <code>document.stylesheets</code> object and it&#8217;s functions are woefully supported in other browsers, Safari in particular.</p>
<p>My next attempt was a tad more successful - I used <code>document.createElement("style")</code>, appended the rules to it as a TextNode, and then appended the style to the <code>&lt;head&gt;</code>.  I then learned that IE does not like to append TextNodes to style elements.</p>
<p>So, after a bit of research I found a way to get IE to insert the text into the style.  It works in the latest-greatest Mozilla, IE, Safari, and Opera.  Not sure about older versions.  Just have it run <code>onLoad()</code> and make an example <code>div</code> to test it out.</p>
<pre>
var myCSS = "div{background-color: blue}";
var myStyle = document.createElement("style");
	myStyle.setAttribute("type", "text/css");

//only IE uses style.styleSheet, the rest use style.sheet
if(myStyle.styleSheet){
	//Many browsers won't let you change the style's cssText, but IE does.
	myStyle.styleSheet.cssText = myCSS;
} else {
	//this is the standard way to do it, which IE does not support.
	myCSS = document.createTextNode(myCSS);
	myStyle.appendChild(myCSS);
}

document.getElementsByTagName("head")[0].appendChild(myStyle);
</pre>
<p>Obviously if you don&#8217;t want things to blow up in more archaic browsers, you&#8217;re going to want to do a detect for <code>document.createElement</code> before running this code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.animejb.net/2006/06/29/dynamic-style-sheets/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
