<?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>IdealStyleAndDesign.com &#187; and ‘e.preventDefault’</title>
	<atom:link href="http://www.idealstyleanddesign.com/tag/and%c2%a0%e2%80%98e-preventdefault%e2%80%99/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.idealstyleanddesign.com</link>
	<description>Ideal Style And Design</description>
	<lastBuildDate>Wed, 21 Sep 2011 11:20:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The difference between ‘return false;’ and ‘e.preventDefault();’</title>
		<link>http://www.idealstyleanddesign.com/the-difference-between-%e2%80%98return-false%e2%80%99-and%c2%a0%e2%80%98e-preventdefault%e2%80%99/</link>
		<comments>http://www.idealstyleanddesign.com/the-difference-between-%e2%80%98return-false%e2%80%99-and%c2%a0%e2%80%98e-preventdefault%e2%80%99/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 23:35:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS Styling]]></category>
		<category><![CDATA[and ‘e.preventDefault’]]></category>
		<category><![CDATA[between]]></category>
		<category><![CDATA[difference]]></category>
		<category><![CDATA[false’]]></category>
		<category><![CDATA[‘return]]></category>

		<guid isPermaLink="false">http://www.idealstyleanddesign.com/the-difference-between-%e2%80%98return-false%e2%80%99-and%c2%a0%e2%80%98e-preventdefault%e2%80%99/</guid>
		<description><![CDATA[Have you ever seen those two things (in the title) being used in jQuery? Here is a simple example:
$("a").click(function() {
   $("body").append($(this).attr("href"));
   return false;
}
That code would append the href attribute as text to the body every time a link was clicked but not actually go to that link. The return false; part [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Have you ever seen those two things (in the title) being used in jQuery? Here is a simple example:</p>
<pre><code class="javascript">$("a").click(function() {
   $("body").append($(this).attr("href"));
   return false;
}</code></pre>
<p>That code would append the <tt>href</tt> attribute as text to the body every time a link was clicked but <strong>not</strong> actually go to that link. The <tt>return false;</tt> part of that code prevents the browser from performing the default action for that link. That exact thing could be written like this:</p>
<pre><code class="javascript">$("a").click(function(e) {
   $("body").append($(this).attr("href"));
   e.preventDefault();
}</code></pre>
<p>So what&#8217;s the difference?</p>
<p><span id="more-6809"></span></p>
<p>The difference is that <tt>return false;</tt> takes things a bit further in that it also prevents that event from propagating (or &#8220;bubbling up&#8221;) the DOM. The you-may-not-know-this bit is that whenever an event happens on an element, that event is triggered on every single parent element as well. So let&#8217;s say you have a box inside a box. Both boxes have click events on them. Click on the inner box, a click will trigger on the outer box too, unless you prevent propagation. Like this:</p>
<div class="image-wrap"> <img src="http://cdn.css-tricks.com/wp-content/uploads/2010/07/propegationdemo.png" alt="" title="propegationdemo" width="570" height="605" class="alignnone size-full wp-image-6810" /><br /> This demo.</div>
<p>So in other words:</p>
<pre><code class="javascript">function() {
  return false;
}

// IS EQUAL TO

function(e) {
  e.preventDefault();
  e.stopPropagation();
}</code></pre>
<p>It&#8217;s all probably a lot more complicated than this and articles like this probably explain it all a lot better.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.idealstyleanddesign.com/the-difference-between-%e2%80%98return-false%e2%80%99-and%c2%a0%e2%80%98e-preventdefault%e2%80%99/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

