Don't fire onfocus when selecting text?
<p>I'm writing a JavaScript chatting application, but I'm running into a minor problem.</p>

<p>Here is the HTML structure:</p>

<pre><code>&lt;div id="chat"&gt;
    &lt;div id="messages"&gt;&lt;/div&gt;
    &lt;textarea&gt;&lt;/textarea&gt;
&lt;/div&gt;
</code></pre>

<p>When the user clicks/focuses on the chat box, I want the textbox to be automatically focused. I have this <code>onfocus</code> handler on the chat box:</p>

<pre><code>chat.onfocus = function () {
    textarea.focus();
}
</code></pre>

<p>This works, but the problem is that in Firefox, this makes it impossible to select text in the messages <code>div</code>, since when you try to click on it, the focus shifts to the <code>textarea</code>. How can I avoid this problem?</p>

<p>(Semi-related issues: In Chrome, <code>textarea.focus()</code> doesn't seem to shift the keyboard focus to the <code>textarea</code>; it only highlights the box.  IE8 does not seem to respond to the <code>onfocus</code> at all when clicking, even if it <code>tabindex</code> is set. Any idea why?)</p>
