Let's say I have the following HTML:
<div>
<span>span text</span> div text <span>some more text</span>
</div>
I want to make it so that when I click on the span, it triggers some kind of event (for example, to make the text bold), which is easy:
$('span').click( ... )
But now, when I click on an element, I want another event to fire (for example, to make the text normal weight). I need to somehow detect a click not inside the span element. This is very similar to the blur () event, but not for INPUT elements. I do not mind if this click is found only inside the DIV element, and not the entire BODY page, by the way.
I tried to get an event to fire on elements other than SPAN, with the following:
$('div').click( ... )
$('div').not('span').click( ... )
$('div').add('span').click( ... )
Another solution would be to read the event target inside the click event. Here is an example implementation of this method:
$('div').click(function(e) {
if (e.target.nodeName != "span")
...
});
, , blur().