<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Prototype and jQuery</title>
	<atom:link href="http://www.barneyb.com/barneyblog/2008/05/07/prototype-and-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.barneyb.com/barneyblog/2008/05/07/prototype-and-jquery/</link>
	<description>Thoughts, rants, and even some code from the mind of Barney Boisvert.</description>
	<lastBuildDate>Thu, 11 Sep 2014 09:58:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Kent Fredric</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/07/prototype-and-jquery/comment-page-1/#comment-142474</link>
		<dc:creator>Kent Fredric</dc:creator>
		<pubDate>Fri, 21 Nov 2008 14:05:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=389#comment-142474</guid>
		<description>For jQuery code blocks that are self-contained and collision friendly there is this handy notation


jQuery(function($){ 
     
  $(&quot;.foo&quot;); // Use like you would normally. 

}); 

This does the following.

1) Encapsulates the code cleanly so as not to leak into the dom. 
2) Waits for the DOM to be ready before executing
3) Executes the function passing the jQuery object in as $ 

This way $ doesn&#039;t exist outside this function, but does inside it, immeasurably helpful.</description>
		<content:encoded><![CDATA[<p>For jQuery code blocks that are self-contained and collision friendly there is this handy notation</p>
<p>jQuery(function($){ </p>
<p>  $(".foo"); // Use like you would normally. </p>
<p>}); </p>
<p>This does the following.</p>
<p>1) Encapsulates the code cleanly so as not to leak into the dom.<br />
2) Waits for the DOM to be ready before executing<br />
3) Executes the function passing the jQuery object in as $ </p>
<p>This way $ doesn't exist outside this function, but does inside it, immeasurably helpful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ù…Ø­Ù…Ø¯ Ø²Ø§Ù‡Ø± ØºÙŠØ¨Ø© &#187; Ø§Ù„Ø£Ø±Ø´ÙŠÙ &#187; Ø£Ø®Ø¨Ø§Ø± Ù…ØªÙ†ÙˆØ¹Ø© Ù…Ù† Ø§Ù„ÙˆÙŠØ¨</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/07/prototype-and-jquery/comment-page-1/#comment-87141</link>
		<dc:creator>Ù…Ø­Ù…Ø¯ Ø²Ø§Ù‡Ø± ØºÙŠØ¨Ø© &#187; Ø§Ù„Ø£Ø±Ø´ÙŠÙ &#187; Ø£Ø®Ø¨Ø§Ø± Ù…ØªÙ†ÙˆØ¹Ø© Ù…Ù† Ø§Ù„ÙˆÙŠØ¨</dc:creator>
		<pubDate>Fri, 09 May 2008 20:16:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=389#comment-87141</guid>
		<description>[...] .. * Ùˆ Ø£Ø®ÙŠØ±Ø§Ù‹ Ùˆ Ù„ÙŠØ³ Ø¢Ø®Ø±Ø§Ù‹ ØŒ Ù…Ù‚Ø§Ù„ Ù…Ù‚Ø§Ø±Ù†Ø© Ø¬Ø¯ÙŠØ¯ Ø¨ÙŠÙ† Ø§Ù„Ø¨Ø·Ù„ÙŠÙ† Prototype and jQuery &#8230; Ù…Ù„Ø§Ø­Ø¸Ø© : Ù…Ù†Ø° ÙØªØ±Ø© ØªÙ… Ø§Ù†Ø²Ø§Ù„ Ø§Ù„Ù†Ø³Ø®Ø© Ø§Ù„ØªØ¬Ø±ÙŠØ¨ÙŠØ© [...]</description>
		<content:encoded><![CDATA[<p>[...] .. * Ùˆ Ø£Ø®ÙŠØ±Ø§Ù‹ Ùˆ Ù„ÙŠØ³ Ø¢Ø®Ø±Ø§Ù‹ ØŒ Ù…Ù‚Ø§Ù„ Ù…Ù‚Ø§Ø±Ù†Ø© Ø¬Ø¯ÙŠØ¯ Ø¨ÙŠÙ† Ø§Ù„Ø¨Ø·Ù„ÙŠÙ† Prototype and jQuery &#8230; Ù…Ù„Ø§Ø­Ø¸Ø© : Ù…Ù†Ø° ÙØªØ±Ø© ØªÙ… Ø§Ù†Ø²Ø§Ù„ Ø§Ù„Ù†Ø³Ø®Ø© Ø§Ù„ØªØ¬Ø±ÙŠØ¨ÙŠØ© [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Nathanson</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/07/prototype-and-jquery/comment-page-1/#comment-86835</link>
		<dc:creator>Josh Nathanson</dc:creator>
		<pubDate>Thu, 08 May 2008 23:00:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=389#comment-86835</guid>
		<description>Crap, my html tags got eaten up in the above code example.  I had put that &quot;Hello&quot; within a div tag as if to create a div on the fly.</description>
		<content:encoded><![CDATA[<p>Crap, my html tags got eaten up in the above code example.  I had put that "Hello" within a div tag as if to create a div on the fly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Nathanson</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/07/prototype-and-jquery/comment-page-1/#comment-86834</link>
		<dc:creator>Josh Nathanson</dc:creator>
		<pubDate>Thu, 08 May 2008 22:58:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=389#comment-86834</guid>
		<description>What&#039;s nice about $() returning jQuery rather than a DOM node, is that you can then chain methods like so:
$(&quot;Hello&quot;).appendTo(&quot;body&quot;).css(&quot;background-color&quot;,&quot;red&quot;);

Maybe Prototype has some other way to accomplish this sort of thing;  I&#039;ve not used it.

Then if you want the DOM node you can always get it in the manner you mentioned;  but like Dan said, I rarely find myself needing to do that, while I am constantly chaining methods.</description>
		<content:encoded><![CDATA[<p>What's nice about $() returning jQuery rather than a DOM node, is that you can then chain methods like so:<br />
$("Hello").appendTo("body").css("background-color","red");</p>
<p>Maybe Prototype has some other way to accomplish this sort of thing;  I've not used it.</p>
<p>Then if you want the DOM node you can always get it in the manner you mentioned;  but like Dan said, I rarely find myself needing to do that, while I am constantly chaining methods.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/07/prototype-and-jquery/comment-page-1/#comment-86694</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Thu, 08 May 2008 16:28:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=389#comment-86694</guid>
		<description>John, George, Brian, and Dan:

I know about jQuery&#039;s $() function, but it returns jQuery, not a DOM node.  There&#039;s a difference.  As Dan points out, it also requires supplying a hash in the string, rather than just the bare ID.  I am running in noConflict mode to ensure that any lingering $() calls (to Prototype) are fast-fail, but that&#039;s not a requirement of Prototype&#039;s class framework - it&#039;s $ agnostic.

Like I said at the end of the post, I&#039;m in the conversion process at the moment, so the differences are glaring, regardless of their actual effect.  The more significant issue is definitely the performance (and it&#039;s ramifications), since that won&#039;t go away as the conversion comes to a close.</description>
		<content:encoded><![CDATA[<p>John, George, Brian, and Dan:</p>
<p>I know about jQuery's $() function, but it returns jQuery, not a DOM node.  There's a difference.  As Dan points out, it also requires supplying a hash in the string, rather than just the bare ID.  I am running in noConflict mode to ensure that any lingering $() calls (to Prototype) are fast-fail, but that's not a requirement of Prototype's class framework &#8211; it's $ agnostic.</p>
<p>Like I said at the end of the post, I'm in the conversion process at the moment, so the differences are glaring, regardless of their actual effect.  The more significant issue is definitely the performance (and it's ramifications), since that won't go away as the conversion comes to a close.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan G. Switzer, II</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/07/prototype-and-jquery/comment-page-1/#comment-86627</link>
		<dc:creator>Dan G. Switzer, II</dc:creator>
		<pubDate>Thu, 08 May 2008 13:09:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=389#comment-86627</guid>
		<description>$() is already a shortcut for jQuery(), but as you mention some people miss the $() = DOM object so you might want to do this instead:

function $$(id){ return jQuery(&quot;#&quot;+id)[0]; }

Personally, I rarely deal with raw DOM elements anymore. Also, we&#039;ll getting used to the CSS-style selectors was something I wasn&#039;t fond of at first (since I thought have to write &quot;#id&quot; was a bit of a PITA,) I&#039;ve since come to like it. I find it makes switching between writing CSS rules and jQuery much easier and it&#039;s more clear.</description>
		<content:encoded><![CDATA[<p>$() is already a shortcut for jQuery(), but as you mention some people miss the $() = DOM object so you might want to do this instead:</p>
<p>function $$(id){ return jQuery("#"+id)[0]; }</p>
<p>Personally, I rarely deal with raw DOM elements anymore. Also, we'll getting used to the CSS-style selectors was something I wasn't fond of at first (since I thought have to write "#id" was a bit of a PITA,) I've since come to like it. I find it makes switching between writing CSS rules and jQuery much easier and it's more clear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Swartzfager</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/07/prototype-and-jquery/comment-page-1/#comment-86600</link>
		<dc:creator>Brian Swartzfager</dc:creator>
		<pubDate>Thu, 08 May 2008 11:58:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=389#comment-86600</guid>
		<description>You can use &#039;$(&quot;#elementId&quot;)&#039; instead of &#039;jQuery(&quot;#elementId&quot;)&#039; in your jQuery functions by default so long as that doesn&#039;t cause a conflict with another JavaScript library you&#039;re using--see &lt;a href=&quot;http://docs.jquery.com/Using_jQuery_with_Other_Libraries&quot; rel=&quot;nofollow&quot;&gt;Using jQuery with Other Libraries&lt;/a&gt;.

You mentioned that you&#039;re still using the Prototype class framework in conjunction with jQuery, so that&#039;s why you may need to use the more verbose jQuery call.</description>
		<content:encoded><![CDATA[<p>You can use '$("#elementId")' instead of 'jQuery("#elementId")' in your jQuery functions by default so long as that doesn't cause a conflict with another JavaScript library you're using&#8211;see <a href="http://docs.jquery.com/Using_jQuery_with_Other_Libraries" rel="nofollow">Using jQuery with Other Libraries</a>.</p>
<p>You mentioned that you're still using the Prototype class framework in conjunction with jQuery, so that's why you may need to use the more verbose jQuery call.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: George Bridgeman</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/07/prototype-and-jquery/comment-page-1/#comment-86535</link>
		<dc:creator>George Bridgeman</dc:creator>
		<pubDate>Thu, 08 May 2008 08:54:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=389#comment-86535</guid>
		<description>&quot;The lack of the $() function is annoying&quot;

There is a $ function in jQuery, which is just the same as the jQuery function. Not sure what would make you think the $ function didn&#039;t exist. I&#039;ve been using it for months!

There&#039;s a big advantage of jQuery over Prototype but it&#039;s very situational. If you&#039;re writing a JS library which uses jQuery, you obviously don&#039;t want to interfere with the $ (and perhaps jQuery) function if your client is using Prototype, another version of jQuery, or has their own implementation of either of these functions. jQuery provides the noConflict method which will let you put the $ function into your own variable and put whatever was in there originally, back in.

Say a client is using the $ function Prototype, then I go include jQuery using my library. jQuery can put Prototype back into window.$ and return a reference to jQuery&#039;s $ function for you to put into your own variable for use internally by your own library. So instead of doing $(&#039;#theId&#039;), you&#039;d do jq(&#039;#theId&#039;), for example.

Like I said, it&#039;s very situational, but it&#039;s something jQuery has which Prototype doesn&#039;t (as far as I can tell so far).

Hope this makes sense!

George.</description>
		<content:encoded><![CDATA[<p>"The lack of the $() function is annoying"</p>
<p>There is a $ function in jQuery, which is just the same as the jQuery function. Not sure what would make you think the $ function didn't exist. I've been using it for months!</p>
<p>There's a big advantage of jQuery over Prototype but it's very situational. If you're writing a JS library which uses jQuery, you obviously don't want to interfere with the $ (and perhaps jQuery) function if your client is using Prototype, another version of jQuery, or has their own implementation of either of these functions. jQuery provides the noConflict method which will let you put the $ function into your own variable and put whatever was in there originally, back in.</p>
<p>Say a client is using the $ function Prototype, then I go include jQuery using my library. jQuery can put Prototype back into window.$ and return a reference to jQuery's $ function for you to put into your own variable for use internally by your own library. So instead of doing $('#theId'), you'd do jq('#theId'), for example.</p>
<p>Like I said, it's very situational, but it's something jQuery has which Prototype doesn't (as far as I can tell so far).</p>
<p>Hope this makes sense!</p>
<p>George.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Whish</title>
		<link>https://www.barneyb.com/barneyblog/2008/05/07/prototype-and-jquery/comment-page-1/#comment-86533</link>
		<dc:creator>John Whish</dc:creator>
		<pubDate>Thu, 08 May 2008 08:49:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=389#comment-86533</guid>
		<description>I use jQuery a lot and refer to elements by id. I might be missing the point but doesn&#039;t this shorthand do what you want?

$(function(){
  reference = $(&#039;#myelement&#039;);
});

as an id should be unique you don&#039;t need to reference the first element in the array.</description>
		<content:encoded><![CDATA[<p>I use jQuery a lot and refer to elements by id. I might be missing the point but doesn't this shorthand do what you want?</p>
<p>$(function(){<br />
  reference = $('#myelement');<br />
});</p>
<p>as an id should be unique you don't need to reference the first element in the array.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
