<?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>Andrew Marconi &#187; jquery</title>
	<atom:link href="http://andrewmarconi.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewmarconi.com</link>
	<description>UX-Focused Technical Project Manager, Developer and Digital Producer</description>
	<lastBuildDate>Fri, 18 May 2012 19:24:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Troubleshooting jQuery in WordPress Themes</title>
		<link>http://andrewmarconi.com/2009/05/troubleshooting-jquery-in-wordpress-themes/</link>
		<comments>http://andrewmarconi.com/2009/05/troubleshooting-jquery-in-wordpress-themes/#comments</comments>
		<pubDate>Fri, 29 May 2009 04:29:03 +0000</pubDate>
		<dc:creator>Andrew Marconi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[troubleshoot]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://andrewmarconi.com/?p=128</guid>
		<description><![CDATA[Here&#8217;s another &#8220;oh yeah, I always forget about that&#8221; geek item. I spent a few hours today going nuts trying to figure out why the jQuery Cycle plug-in wasn&#8217;t working in a new theme I&#8217;m working on. The code ran &#8230; <a href="http://andrewmarconi.com/2009/05/troubleshooting-jquery-in-wordpress-themes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s another &#8220;oh yeah, I always forget about that&#8221; geek item.</p>
<p>I spent a few hours today going nuts trying to figure out why the <a href="http://www.malsup.com/jquery/cycle/" target="_blank">jQuery Cycle plug-in</a> wasn&#8217;t working in a new theme I&#8217;m working on. The code ran great outside of WordPress, but the minute I placed it inside the theme, it broke.</p>
<p>Then I realized: when using <a href="http://jquery.com/" target="_blank">jQuery</a> in <a href="http://www.wordpress.org/" target="_blank">WordPress</a> you always have to remember to explicitly call it by name rather than use the handy-dandy $(&#8220;#identifier&#8221;) short-cut that every example and demo online uses. The long-winded reasoning (as I discovered thanks to <a href="http://techxplorer.com/2008/02/25/using-jquery-with-wordpress/" target="_blank">Techxplorer&#8217;s blog entry</a>) is that the bundled version of jQuery built into WordPress since version 2.2 is initialized with <a href="http://docs.jquery.com/Core/jQuery.noConflict" target="_blank">jQuery.noConflict</a>. The upside is that this keeps the jQuery library from crashing into other bundled libraries (like <a href="http://www.prototypejs.org/" target="_blank">Prototype</a>). The bad news is that it breaks support for the $ shortcut.<br />
<span id="more-128"></span><br />
I came across an simple solution via <a href="http://chrismeller.com/2007/07/using-jquery-in-wordpress" target="_blank">Chris Mellon</a>:</p>
<blockquote><p>Instead, for interoperability, be sure to use <code>jQuery()</code> instead, which should accomplish the same thing.</p>
<p>A bad example:</p>
<pre class="javascript geshicode" style="font-family: monospace;"><span style="color: #003366; font-weight: bold;">var</span> username <span style="color: #339933;">=</span> $<span style="color: #009900;">(</span><span style="color: #3366cc;">'#username'</span><span style="color: #009900;">)</span>.<span style="color: #660066;">val</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre>
<p>If Prototype were to be loaded on the page this snippet of <acronym title="JavaScript"><span class="caps">JS</span></acronym> is running on, it would throw an error, since it uses a different pattern for selecting <acronym title="Document Object Model"><span class="caps">DOM</span></acronym> elements.</p>
<p>A good example:</p>
<pre class="javascript geshicode" style="font-family: monospace;"><span style="color: #003366; font-weight: bold;">var</span> username <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">(</span><span style="color: #3366cc;">'#username'</span><span style="color: #009900;">)</span>.<span style="color: #660066;">val</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre>
<p>This line should work on any page, regardless of library conflicts. It’s a couple extra characters to type, but in the end it’s really for the best &#8211; you get portability, and it’s more self-explanatory which library is being used when you go back to look at this code in 6 months.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://andrewmarconi.com/2009/05/troubleshooting-jquery-in-wordpress-themes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

