Best way to check JavaScript object's value if object may be undefined
<p>I have a <code>textarea</code> that I have a blur event attached to. I don't want the blur event to run if the user clicks on a specific <code>span.dontClick</code> on the page. However if the user clicks on anything other than the <code>span.dontClick</code> I do want the blur event to run. I have found a way to do this, but it looks awful, feels very hackey, and I'm guessing there is a better solution out there. Here's what I've come up with:</p>

<pre><code>if (event.type === 'focusout') {
  if (
    typeof event.originalEvent !== 'undefined' &amp;&amp;
    typeof event.originalEvent.currentTarget !== 'undefined' &amp;&amp;
    typeof event.originalEvent.currentTarget.activeElement !== 'undefined' &amp;&amp;
    typeof event.originalEvent.currentTarget.activeElement.className !== 'undefined' &amp;&amp;
    event.originalEvent.currentTarget.activeElement.className === 'dontClick'
  ) {
    // abort the code for the blur event (in effect, do nothing)
  }
  else {
    // run code for when a user blurs by not clicking on span
  }
</code></pre>

<p>It should probably be noted that the <code>event</code> object is from a jQuery event handler. I'm not sure if it is different or the same as the native <code>event</code> objects.</p>

<p>It should also be noted that this fails silently for most browsers but I get a debug window in IE if I don't specify the 'undefined' state for each object all the way down the line...</p>

<p>If anyone has a more elegant solution I would really appreciate seeing it. Thanks!</p>
