<?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>UTDC Blog &#187; jquery</title>
	<atom:link href="http://www.untrocitodecielo.com/blog/tag/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://www.untrocitodecielo.com/blog</link>
	<description></description>
	<lastBuildDate>Sun, 21 Jun 2009 11:29:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Cambiar css con javascript</title>
		<link>http://www.untrocitodecielo.com/blog/cambiar-css-con-javascript</link>
		<comments>http://www.untrocitodecielo.com/blog/cambiar-css-con-javascript#comments</comments>
		<pubDate>Thu, 28 May 2009 20:00:03 +0000</pubDate>
		<dc:creator>Tijeran</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[destacado]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[cambiar]]></category>
		<category><![CDATA[swift]]></category>

		<guid isPermaLink="false">http://www.untrocitodecielo.com/blog/?p=102</guid>
		<description><![CDATA[Otra de las cosas que acabo de añadir al blog es la posibilidad de cambiar el css dinámicamente usando un par de librerias javascript, además, una cookie guarda el estado para que cada vez que abras de nuevo la página se mantenga el último estilo elegido. El código es tan sencillo como casi todo en [...]]]></description>
			<content:encoded><![CDATA[<p>Otra de las cosas que acabo de añadir al blog es la posibilidad de <strong>cambiar el css dinámicamente</strong> usando un par de librerias<strong> javascript</strong>, además, una cookie guarda el estado para que cada vez que abras de nuevo la página se mantenga el último estilo elegido.</p>
<p>El código es tan <strong>sencillo</strong> como casi todo en jquery, solo tienes que añadir a la cabecera los &#8220;alternates&#8221; de los diferentes <strong>css</strong> e importar tanto <strong>jquery </strong>como el <strong>plugin</strong> de este modo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p102code4'); return false;">Ver código</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1024"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p102code4"><pre class="html" style="font-family:monospace;">	&lt;link rel=&quot;alternate stylesheet&quot; type=&quot;text/css&quot; href=&quot;nuevoEstilo.css&quot; title=&quot;nuevoEstilo&quot; media=&quot;screen&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/wp-includes/js/styleswitch.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/wp-includes/js/jquery.js&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>

<p>El atributo &#8220;title&#8221; es lo que usará el javascript para identificar los css.<br />
<span id="more-102"></span><br />
La función para cambiarlos debe de ir como siempre nada más empezar el &#8220;body&#8221; y no hace falta modificarla en absoluto, sería asi:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p102code5'); return false;">Ver código</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1025"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code" id="p102code5"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</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: #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: #009900;">&#40;</span><span style="color: #3366CC;">'.styleswitch'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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>
         switchStylestyle<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;rel&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> c <span style="color: #339933;">=</span> readCookie<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'style'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span> switchStylestyle<span style="color: #009900;">&#40;</span>c<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>
&nbsp;
   <span style="color: #003366; font-weight: bold;">function</span> switchStylestyle<span style="color: #009900;">&#40;</span>styleName<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'link[@rel*=style][title]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> 
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">disabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
         <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> styleName<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">disabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      createCookie<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'style'</span><span style="color: #339933;">,</span> styleName<span style="color: #339933;">,</span> <span style="color: #CC0000;">365</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Por último, desde los archivos <strong>php</strong> o <strong>html</strong> usamos un enlace para llamar a la función:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p102code6'); return false;">Ver código</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1026"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p102code6"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;serversideSwitch.html?style=nuevoEstilo&quot; rel=&quot;nuevoEstilo&quot; class=&quot;styleswitch&quot;&gt;Cambiar estilo css...&lt;/a&gt;</pre></td></tr></table></div>

<p>Podeis verlo en funcionamiento en el menú de arriba o en la <a href="http://www.kelvinluck.com/assets/jquery/styleswitch/">página web del autor</a>.</p>
<p>Fuente: <a href="http://www.kelvinluck.com/2006/05/switch-stylesheets-with-jquery/">KelvinLuck.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.untrocitodecielo.com/blog/cambiar-css-con-javascript/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

