<?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>Barryvan &#187; onblur</title>
	<atom:link href="http://www.barryvan.com.au/tag/onblur/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.barryvan.com.au</link>
	<description>Music, Programming, Design</description>
	<lastBuildDate>Sun, 08 Jan 2012 08:48:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Cross-browser div focus and blur</title>
		<link>http://www.barryvan.com.au/2009/01/onfocus-and-onblur-for-divs-in-fx/</link>
		<comments>http://www.barryvan.com.au/2009/01/onfocus-and-onblur-for-divs-in-fx/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 13:28:21 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[blur]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[focus]]></category>
		<category><![CDATA[onblur]]></category>
		<category><![CDATA[onfocus]]></category>
		<category><![CDATA[popup]]></category>

		<guid isPermaLink="false">http://barryvan.com.au/wp/?p=66</guid>
		<description><![CDATA[Internet Explorer has for some time supported giving &#8216;focus&#8217; to non-focussable elements such as divs. Firefox, by contrast, does not. Whilst this makes sense semantically, it&#8217;s often still very useful to use these triggers. For example, you can use onfocus to show a popup when a div is clicked, and close the popup when anything [...]]]></description>
			<content:encoded><![CDATA[<p>Internet Explorer has for some time supported giving &#8216;focus&#8217; to non-focussable elements such as <code>div</code>s. Firefox, by contrast, does not. Whilst this makes sense semantically, it&#8217;s often still very useful to use these triggers. For example, you can use <code>onfocus</code> to show a popup when a div is clicked, and close the popup when anything else is clicked on the page (in the <code>onblur</code> event).</p>
<p>There are many, many workarounds which provide this functionality, using such tricks as hidden input elements, global <code>onclick</code> handlers, and so on, but the simplest is simply this: <em>give your <code>div</code> a <code>tabIndex</code> attribute</em>. For example,</p>
<div><code>&lt;div tabindex="-1" onfocus="document.getElementById('monkey').style.display='block'" onblur="document.getElementById('monkey').style.display='none'"&gt;Click to show another div.&lt;/div&gt;<br />
&lt;div id="monkey" style="display:none;"&gt;Click elsewhere to hide this div.&lt;/div&gt;<br />
</code></div>
<p>works perfectly in Firefox, Internet Explorer, and Chrome as shown in the example below:</p>
<div style="background-color:#080808;border:solid 1px #222222;padding:4px;margin-left:64px;margin:8px;margin-right:64px;color:#dddddd;" onfocus="document.getElementById('monkey').style.display='block'" onblur="document.getElementById('monkey').style.display='none'" tabIndex="-1">Click to show another div.</div>
<div id="monkey" style="background-color:#222222;border:solid 1px #444444;display:none;padding:4px;margin-bottom:8px;margin-left:64px;margin-right:64px;color:#dddddd;">Click elsewhere to hide this div.</div>
<p>The value of <code>tabIndex</code> can have significance, too:</p>
<ul>
<li><strong>-1</strong>: The user can&#8217;t tab to the element, but it can be given focus programmatically (<code>element.focus()</code>) or by being clicked on.</li>
<li><strong>0</strong>: The user can tab to the element, and its order in the tabbing is automatically determined.</li>
<li><strong>&gt;0</strong>: Give the element a priority, with &#8217;1&#8242; being the highest priority.</li>
</ul>
<p>I originally discovered this technique on <a href="http://codingforums.com/showthread.php?t=134792" target="_blank">this CodingForums.com thread</a>.</p>
<div><strong>Supporting browsers:</strong></div>
<ul>
<li>Firefox</li>
<li>Internet Explorer</li>
<li>Google Chrome</li>
</ul>
<div><strong>Non-supporting browsers:</strong></div>
<ul>
<li>Safari</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/01/onfocus-and-onblur-for-divs-in-fx/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

