<?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>eli geske &#187; JQuery</title>
	<atom:link href="http://eligeske.com/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://eligeske.com</link>
	<description>Good information for the geeky kind.</description>
	<lastBuildDate>Wed, 25 Jan 2012 00:20:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>JQuery parent() vs. parents() Which is faster?</title>
		<link>http://eligeske.com/jquery/jquery-parent-vs-parents-which-is-faster/</link>
		<comments>http://eligeske.com/jquery/jquery-parent-vs-parents-which-is-faster/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 18:42:07 +0000</pubDate>
		<dc:creator>eligeske</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[find parent]]></category>
		<category><![CDATA[find parents]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[parents]]></category>
		<category><![CDATA[traversing]]></category>

		<guid isPermaLink="false">http://eligeske.com/?p=507</guid>
		<description><![CDATA[I have been wondering which method of traversing up the DOM is faster using the jQuery library's options, parent() and parents(). Well I'll show you my findings.]]></description>
			<content:encoded><![CDATA[<p><strong>In most cases <span style="text-decoration: underline;">parent()</span> is faster&#8230;. here is why</strong></p>
<p>If you are here, I am sure you already know about jQuery&#8217;s parent() method and parents() method.  What I ended up doing to find out which one was faster was to create a simple benchmark test using only FireFox. This result sufficed for me but it may differ with each browser engine.</p>
<p><strong>Test Scenario:</strong> HTML page consisting of nested div&#8217;s. Thirty in total. I set an id and class at parent number 2, 5, 15, and 30.  Then I used jQuery&#8217;s parent(), parents(&#8216;#id&#8217;), and parents(&#8216;.class&#8217;) to find out which one was the speediest.</p>
<p>I created a click function which I hit 10 times for each test and captured the execution time and how many underlying method calls were made for each group of ten clicks. Those are displayed as the &#8220;calls&#8221;. The times are display as &#8220;time&#8221; but are in milliseconds. So if it says 5.23, it is actually 5.23 milliseconds. The number of nodes traversed up is marked as &#8220;nodes&#8221;.</p>
<p><strong>Functions:</strong> here is what the functions I used looked like</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">function findParent(obj){         
        $val = obj.parent().parent().parent().parent().parent().attr('class');
        $('#output').val($val);
    }
&nbsp;
    function findParents(obj){
        $val = obj.parents('.toppest').attr('class');
        $('#output').val($val);
    }
&nbsp;
    function findParents2(obj){
        $val = obj.parents('#topClass2').attr('class');
        $('#output').val($val);
    }
&nbsp;
    $(function(){               
        $('#child').click(function(){
            findParent($(this));                           
        });
        $('#child2').click(function(){
            findParents($(this));                           
        });    
        $('#child3').click(function(){
            findParents2($(this));                           
        });
    });</pre></div>
<p>&nbsp;</p>
<p>Notice on the find <span style="text-decoration: underline;">parent</span> method how many times .parents() is added. Can you imagine doing that for thirty nodes? ya&#8230;.  that&#8217;s why I added the little value to a box when I clicked it to make sure I was grabbing the right one for test purposes. It really had nothing to do with the benchmark but since it was consistent across each one it does not screw with the test.</p>
<p><strong>Averaged Results:</strong></p>
<div class="datagrid">
<table width="460" border="0" cellspacing="0" cellpadding="0">
<colgroup>
<col width="23" />
<col width="45" />
<col width="48" />
<col width="78" />
<col width="54" />
<col width="84" />
<col span="2" width="64" /> </colgroup>
<thead>
<tr>
<th rowspan="2" width="23" height="40">x&#8217;s</th>
<th rowspan="2" width="45">nodes</th>
<th colspan="2" width="126">parent()</th>
<th colspan="2" width="138">parents() by class</th>
<th colspan="2" width="128">parents() by id</th>
</tr>
<tr>
<th height="20">time</th>
<th> calls</th>
<th>time</th>
<th>calls</th>
<th>time</th>
<th>calls</th>
</tr>
</thead>
<tbody>
<tr>
<td height="20">10</td>
<td>2</td>
<td style="font-weight: bold; text-decoration: underline">3.435</td>
<td>420</td>
<td>4.412</td>
<td>460</td>
<td>4.607</td>
<td>780</td>
</tr>
<tr class="alt">
<td height="20">10</td>
<td>5</td>
<td style="font-weight: bold; text-decoration: underline">3.989</td>
<td>600</td>
<td>4.407</td>
<td>460</td>
<td>4.665</td>
<td>780</td>
</tr>
<tr>
<td height="20">10</td>
<td>15</td>
<td>5.175</td>
<td>1200</td>
<td style="font-weight: bold; text-decoration: underline">4.504</td>
<td>460</td>
<td>4.644</td>
<td>780</td>
</tr>
<tr class="alt">
<td height="20">10</td>
<td>30</td>
<td>7.113</td>
<td>2100</td>
<td style="font-weight: bold; text-decoration: underline">4.579</td>
<td>460</td>
<td>4.956</td>
<td>780</td>
</tr>
</tbody>
</table>
</div>
<p><span style="color: #888; font-size: 10px;"> I made this table look pretty with <a href="http://tablestyler.com">tablestyler.com</a></span></p>
<p><strong>Findings:</strong></p>
<p>The results of the test are that using parent() even though not as clean looking in the code is actually faster for smaller traversing. But as you get farther up the DOM tree away from your child element parent() slows down.</p>
<p>Using parents() is pretty consistent all the way across the board with only a slight increase in time to complete the call whether your nested forty in or only one down. Plus keeps you from writing parent() ten or twenty times over.</p>
<p><strong>My Suggestions:</strong></p>
<p>I would use parent() for anything under 5 or 6 away from the child and use parents() every where else. That is of course if you know what element you&#8217;re look for exactly. Then in that case you may need to use the parents() method.</p>
<p>P.S. I hope your HTML never has an element that is nested 30 down. If so, you are probably using .NET</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://eligeske.com/jquery/jquery-parent-vs-parents-which-is-faster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery bind and clone, what&#8217;s the deal?</title>
		<link>http://eligeske.com/jquery/jquery-bind-and-clone-whats-the-deal/</link>
		<comments>http://eligeske.com/jquery/jquery-bind-and-clone-whats-the-deal/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 21:07:33 +0000</pubDate>
		<dc:creator>eligeske</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[clone]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[methods]]></category>

		<guid isPermaLink="false">http://eligeske.com/?p=501</guid>
		<description><![CDATA[jQuery cloning dropping the bind methods. Fix.]]></description>
			<content:encoded><![CDATA[<p>First off, what is clone()?</p>
<p>clone() allows you to make exact copy of that dom element without actually grabbing the one the you are cloning.  If you didn&#8217;t want to move a div and just wanted a copy, you would clone it.</p>
<p>Bind? Attaching an event handler to a specific DOM element.</p>
<p>If you make an Element using jQuery, like so:</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">// Creating a div element with jQuery
var myDiv = $(&quot;&lt;div&gt;&quot;, text: &quot;CLICKEE!&quot;, { click: function(){ alert('YO!'); } });
// put it on the page
myDiv.appendTo('body');</pre></div>
<p>You would see the text CLICKEE on the page, and if you clicked it you would get an alert saying YO!.<br />
Then want to make a couple copies like this:</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">// clone original
var myDivClone = myDiv.clone();
// put it on the page
myDivClone.appendTo('body');</pre></div>
<p>You would see again another CLICKEE on the page, but if you clicked it, nothing would happen. Why? When using the jQuery clone it does not clone the events, unless you pass a true into the parameter like so:</p>
<div class="wp-synhighlighter-inner"><pre class="javascript" style="font-family:arial;">// clone original
 var myDivClone = myDiv.clone(true);
 // put it on the page
 myDivClone.appendTo('body');</pre></div>
<p>&nbsp;</p>
<p>Now you see the CLICKEE and the alert.</p>
]]></content:encoded>
			<wfw:commentRss>http://eligeske.com/jquery/jquery-bind-and-clone-whats-the-deal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

