<?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>click &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/click/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>cancel bubbling on element click with jQuery</title>
		<link>/2009/07/29/cancel-bubbling-on-element-click-with-jquery/</link>
		<comments>/2009/07/29/cancel-bubbling-on-element-click-with-jquery/#respond</comments>
		<pubDate>Wed, 29 Jul 2009 14:09:53 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[bubbling]]></category>
		<category><![CDATA[click]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">/?p=713</guid>
		<description><![CDATA[When you click over an element This is easy, on the element can be attached event listener an such event listener is built in as the click event is. It&#8217;s simply like that: &#60;div click="func1()"&#62;&#60;/div&#62; This with jQuery A bit different with jQuery, but with the same effect is: $('div').click(func1); When there is a bubbling? &#8230; <a href="/2009/07/29/cancel-bubbling-on-element-click-with-jquery/" class="more-link">Continue reading <span class="screen-reader-text">cancel bubbling on element click with jQuery</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/06/17/mouseclick-outside-a-dom-element/" rel="bookmark" title="mouseclick outside a DOM element">mouseclick outside a DOM element </a></li>
<li><a href="/2009/10/22/event-driven-programming-with-jquery-part-3-what-is-a-module/" rel="bookmark" title="Event driven programming with jQuery &#8211; (part 3). What is a module?">Event driven programming with jQuery &#8211; (part 3). What is a module? </a></li>
<li><a href="/2009/07/08/jquery-check-for-element-visibility/" rel="bookmark" title="jQuery check for element visibility">jQuery check for element visibility </a></li>
<li><a href="/2009/12/30/jquery-live-vs-bind-performance/" rel="bookmark" title="jQuery live() vs bind() performance">jQuery live() vs bind() performance </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>When you click over an element</h2>
<p>This is easy, on the element can be attached event listener an such event listener is built in as the click event is. It&#8217;s simply like that:</p>
<blockquote>
<pre>&lt;div click="func1()"&gt;&lt;/div&gt;</pre>
</blockquote>
<h2>This with jQuery</h2>
<p>A bit different with jQuery, but with the same effect is:</p>
<blockquote>
<pre>$('div').click(func1);</pre>
</blockquote>
<h2>When there is a bubbling?</h2>
<p>Well, if you just copy paste this code in your page:</p>
<blockquote>
<pre>$(document).click(<span>function</span>() <span>{ </span></pre>
<pre>    console.log(<span>'clicked on the document'</span>);</pre>
<pre><span>}</span>);
$(<span>'div'</span>).click(<span>function</span>() <span>{ </span></pre>
<pre>    console.log(<span>'clicked on the div'</span>);</pre>
<pre><span>}</span>);</pre>
</blockquote>
<p><a href="/wp-content/uploads/2009/07/cancel-bubbling1.png"><img class="alignnone size-full wp-image-714" title="cancel-bubbling1" src="/wp-content/uploads/2009/07/cancel-bubbling1.png" alt="" width="426" height="182" srcset="/wp-content/uploads/2009/07/cancel-bubbling1.png 426w, /wp-content/uploads/2009/07/cancel-bubbling1-300x128.png 300w" sizes="(max-width: 426px) 100vw, 426px" /></a></p>
<p><em><strong>Note:</strong> if you&#8217;re using Firefox keep the console.log function, in other case you may replace it with either alert or $.log from the recent jQuery </em><a title="jquery debug plugin" href="/2009/07/27/jquery-debug-plugin/" target="_self"><em>plugin</em></a><em> i wrote.</em></p>
<p>Now if you click over the div element you get both messages, cause there is no bubble canceling. If you&#8217;d like to add such canceling, just add this code to the click callback for the div element:</p>
<blockquote>
<pre>return false;</pre>
</blockquote>
<p>and now the code should look like:</p>
<blockquote>
<pre>$(document).click(<span>function</span>() <span>{ </span></pre>
<pre><span>    $.log(<span>'clicked on the document'</span>); </span></pre>
<pre><span><span>}</span>);</span></pre>
<pre>$(<span>'div'</span>).click(<span>function</span>() <span>{ </span></pre>
<pre>    $.log(<span>'clicked on the div'</span>); <span>return false</span>;</pre>
<pre><span>}</span>);</pre>
</blockquote>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/06/17/mouseclick-outside-a-dom-element/" rel="bookmark" title="mouseclick outside a DOM element">mouseclick outside a DOM element </a></li>
<li><a href="/2009/10/22/event-driven-programming-with-jquery-part-3-what-is-a-module/" rel="bookmark" title="Event driven programming with jQuery &#8211; (part 3). What is a module?">Event driven programming with jQuery &#8211; (part 3). What is a module? </a></li>
<li><a href="/2009/07/08/jquery-check-for-element-visibility/" rel="bookmark" title="jQuery check for element visibility">jQuery check for element visibility </a></li>
<li><a href="/2009/12/30/jquery-live-vs-bind-performance/" rel="bookmark" title="jQuery live() vs bind() performance">jQuery live() vs bind() performance </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2009/07/29/cancel-bubbling-on-element-click-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mouseclick outside a DOM element</title>
		<link>/2009/06/17/mouseclick-outside-a-dom-element/</link>
		<comments>/2009/06/17/mouseclick-outside-a-dom-element/#respond</comments>
		<pubDate>Wed, 17 Jun 2009 06:29:42 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[click]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mouseclick]]></category>
		<category><![CDATA[outside]]></category>

		<guid isPermaLink="false">/?p=606</guid>
		<description><![CDATA[What if you have to close on outside mouse click? This situation is kind to be familiar. There is some panel which should be closed on outside click. Yeah, this is the most common usage of the outside click. And to do that is pretty simple. In this tutorial &#8230; jQuery For those of you &#8230; <a href="/2009/06/17/mouseclick-outside-a-dom-element/" class="more-link">Continue reading <span class="screen-reader-text">mouseclick outside a DOM element</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/07/29/cancel-bubbling-on-element-click-with-jquery/" rel="bookmark" title="cancel bubbling on element click with jQuery">cancel bubbling on element click with jQuery </a></li>
<li><a href="/2009/05/25/remove-dom-element-with-jquery/" rel="bookmark" title="Remove DOM Element with JQuery">Remove DOM Element with JQuery </a></li>
<li><a href="/2009/07/04/jquery-check-for-element-existence-in-the-dom/" rel="bookmark" title="jquery check for element existence in the DOM">jquery check for element existence in the DOM </a></li>
<li><a href="/2009/10/22/event-driven-programming-with-jquery-part-3-what-is-a-module/" rel="bookmark" title="Event driven programming with jQuery &#8211; (part 3). What is a module?">Event driven programming with jQuery &#8211; (part 3). What is a module? </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>What if you have to close on outside mouse click?</h2>
<p>This situation is kind to be familiar. There is some panel which should be closed on outside click. Yeah, this is the most common usage of the outside click. And to do that is pretty simple.</p>
<h2>In this tutorial &#8230; jQuery</h2>
<p>For those of you not used to use <a title="jQuery" href="http://jquery.com/" target="_blank">jQuery</a>, in short this is a JavaScript library, which gives you the power to manipulate the DOM with ease. One of the very good parts of jQuery is really the ability to help you with less code to do the hard work of searching and changing the DOM. If you don&#8217;t have any experience with this library, well you can use any other if you&#8217;d like.</p>
<h2>First step: combine the events</h2>
<p>One of the events should be click over the panel, and the other click over the document.<span id="more-606"></span></p>
<p>example in js (jQuery):</p>
<blockquote>
<pre>var clickOverThePanel = false;
var clickOverTheBody = false;

$('#the-panel').click(function() {
    clickOverThePanel = true;
});

$(document).click(function() {
    clickOverTheBody = true;

    if (clickOverTheBody &amp;&amp; !clickOverThePanel)
        $('#the-panel').hide();

});</pre>
</blockquote>
<h2>Where&#8217;s the solution</h2>
<p>Well when you click over the panel you get both document and panel click events registered, and you always get the document.click event. In such way you know that the click somewhere is registered, the only thing is to get if there&#8217;s a click over the panel, and that&#8217;s why you need the check for !clickOverThePanel. Than you finally know if the user has clicked (true), but has not clicked over the panel (false).</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/07/29/cancel-bubbling-on-element-click-with-jquery/" rel="bookmark" title="cancel bubbling on element click with jQuery">cancel bubbling on element click with jQuery </a></li>
<li><a href="/2009/05/25/remove-dom-element-with-jquery/" rel="bookmark" title="Remove DOM Element with JQuery">Remove DOM Element with JQuery </a></li>
<li><a href="/2009/07/04/jquery-check-for-element-existence-in-the-dom/" rel="bookmark" title="jquery check for element existence in the DOM">jquery check for element existence in the DOM </a></li>
<li><a href="/2009/10/22/event-driven-programming-with-jquery-part-3-what-is-a-module/" rel="bookmark" title="Event driven programming with jQuery &#8211; (part 3). What is a module?">Event driven programming with jQuery &#8211; (part 3). What is a module? </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2009/06/17/mouseclick-outside-a-dom-element/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
