<?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>Stylephreak Web Productions &#187; Javascript</title>
	<atom:link href="http://www.stylephreak.com/blog/tag/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.stylephreak.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 24 Sep 2009 07:40:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQuery.loadStylesheet</title>
		<link>http://www.stylephreak.com/blog/coding/jquery-loadstylesheet-5</link>
		<comments>http://www.stylephreak.com/blog/coding/jquery-loadstylesheet-5#comments</comments>
		<pubDate>Mon, 17 Nov 2008 21:30:20 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.stylephreak.com/?p=5</guid>
		<description><![CDATA[<p>I needed a simple function to load a media-specific stylesheet on-the-fly and came up with this jQuery function. You feed it two parameters, the stylesheet name and the media type, and jQuery takes it from there.</p>
<p><span id="more-5"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// load stylesheet(name,media)</span>
loadStylesheet <span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span>m<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'
    &#60;link rel=&#34;style&#8230;</span></pre></div></div>]]></description>
			<content:encoded><![CDATA[<p>I needed a simple function to load a media-specific stylesheet on-the-fly and came up with this jQuery function. You feed it two parameters, the stylesheet name and the media type, and jQuery takes it from there.</p>
<p><span id="more-5"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// load stylesheet(name,media)</span>
loadStylesheet <span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span>m<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'
    &lt;link rel=&quot;stylesheet&quot; href=&quot;'</span><span style="color: #339933;">+</span>e<span style="color: #339933;">+</span><span style="color: #3366CC;">'.css&quot; type=&quot;text/css&quot; media=&quot;'</span><span style="color: #339933;">+</span>m<span style="color: #339933;">+</span><span style="color: #3366CC;">' /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
$<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>
  loadStylesheet<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'test'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'screen'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.stylephreak.com/blog/coding/jquery-loadstylesheet-5/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery.innerWrap</title>
		<link>http://www.stylephreak.com/blog/coding/jquery-innerwrap-8</link>
		<comments>http://www.stylephreak.com/blog/coding/jquery-innerwrap-8#comments</comments>
		<pubDate>Sat, 27 Sep 2008 22:23:59 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.stylephreak.com/blog/?p=8</guid>
		<description><![CDATA[<p>A friend of mine needed a method to wrap the inner content of a tag with another tag, and after a bit of digging around I found that Brandon Aaron, author of the fantastic Dimensions plugin, has created just the thing.</p>
<p><span id="more-8"></span></p>
<blockquote><p>&#8220;jQuery provides a method for wrapping an element with one or more elements. This is a really nice method but sometimes you need to wrap the c&#8230;</p></blockquote>]]></description>
			<content:encoded><![CDATA[<p>A friend of mine needed a method to wrap the inner content of a tag with another tag, and after a bit of digging around I found that <a href="http://blog.brandonaaron.net/2007/06/04/jquery-snippets-innerwrap/" title="jQuery Snippets: innerWrap" rel="external">Brandon Aaron</a>, author of the fantastic Dimensions plugin, has created just the thing.</p>
<p><span id="more-8"></span></p>
<blockquote><p>&#8220;jQuery provides a method for wrapping an element with one or more elements. This is a really nice method but sometimes you need to wrap the contents of an element. Now you can do so with one method, innerWrap. The innerWrap method acts almost identical to the wrap method. The only real difference is that it wraps the contents of the element instead of the actual element.&#8221; &#8211; <span>Brandon Aaron</span></p></blockquote>
<p>Here&#8217;s the function itself:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">innerWrap</span> <span style="color: #339933;">=</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: #003366; font-weight: bold;">var</span> a<span style="color: #339933;">,</span> args <span style="color: #339933;">=</span> arguments<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</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><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>a<span style="color: #009900;">&#41;</span> a <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">clean</span><span style="color: #009900;">&#40;</span>args<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">ownerDocument</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">// Clone the structure that we're using to wrap</span>
        <span style="color: #003366; font-weight: bold;">var</span> b <span style="color: #339933;">=</span> a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">cloneNode</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        c <span style="color: #339933;">=</span> b<span style="color: #339933;">;</span> 
        <span style="color: #006600; font-style: italic;">// Find the deepest point in the wrap structure</span>
        <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>b.<span style="color: #660066;">firstChild</span><span style="color: #009900;">&#41;</span> b <span style="color: #339933;">=</span> b.<span style="color: #660066;">firstChild</span><span style="color: #339933;">;</span> 
        <span style="color: #006600; font-style: italic;">// append the child nodes to the wrapper</span>
        jQuery.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">childNodes</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> node<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            b.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>node<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>
        jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span> 
        <span style="color: #006600; font-style: italic;">// clear the element</span>
        .<span style="color: #660066;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
        <span style="color: #006600; font-style: italic;">// add the new wrapper with the previous child nodes appended</span>
        .<span style="color: #660066;">append</span><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>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And the example below will effectively turn<br />
<strong>&lt;h2&gt;Title&lt;/h2&gt;</strong><br />
into<br />
<strong>&lt;h2&gt;&lt;span&gt;Title&lt;/span&gt;&lt;/h2&gt;</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<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;">'h2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerWrap</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;span&gt;&lt;/span&gt;'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.stylephreak.com/blog/coding/jquery-innerwrap-8/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery.attrToClass</title>
		<link>http://www.stylephreak.com/blog/coding/jquery-attrtoclass-10</link>
		<comments>http://www.stylephreak.com/blog/coding/jquery-attrtoclass-10#comments</comments>
		<pubDate>Wed, 24 Sep 2008 22:25:10 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.stylephreak.com/blog/?p=10</guid>
		<description><![CDATA[<p>I was in need of a very simple function: to append a css class to all form input elements on a page by extracting the input <em>type</em> from the element in question.</p>
<p><span id="more-10"></span></p>
<p>In effect, this:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&#60;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&#34;text&#34;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&#34;name&#34;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&#34;&#34;</span> <span style="color: #66cc66;">/</span>&#62;</span>
<span style="color: #009900;">&#60;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&#34;submit&#34;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&#34;submit&#34;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&#34;Submit&#34;</span> <span style="color: #66cc66;">/</span>&#62;</span></pre></div></div>

<p>b&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>I was in need of a very simple function: to append a css class to all form input elements on a page by extracting the input <em>type</em> from the element in question.</p>
<p><span id="more-10"></span></p>
<p>In effect, this:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>becomes this:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>Until attribute selectors ( <code>input [type=submit] {}</code> ) become the standard, this function will allow me to style my inputs with CSS without having to manually apply classes in my html. The cleaner I can keep my code the happier I am.</p>
<h3>attrToClass Source:</h3>
<p>Comments and suggestions for improvement would be much appreciated:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">attrToClass</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</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>intIndex<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span>e<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>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
$<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;">// designate the tag and the attribute to be extracted</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attrToClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;type&quot;</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></div></div>

<h3>Update</h3>
<p>After playing with this function for a bit I realized it would be just as easy to pull just about any other attribute, from just about any other tags, and apply the classes. Names, for example, would be just as plausible, and probably more versatile, as class name:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submitContact&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
&nbsp;
to
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submitContact&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submitContact&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>With that said, the function has been updated to allow you to designate the tag and attribute type within the function call. Any further updates/fixes will be at this <a href="http://gist.github.com/192588" rel="external">Gist</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.stylephreak.com/blog/coding/jquery-attrtoclass-10/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
