Check if an element is a child of a parent
<p>I have the following code.</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
    &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;div id="hello"&gt;Hello &lt;div&gt;Child-Of-Hello&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div id="goodbye"&gt;Goodbye &lt;div&gt;Child-Of-Goodbye&lt;/div&gt;&lt;/div&gt;

&lt;script type="text/javascript"&gt;
&lt;!--
function fun(evt) {
    var target = $(evt.target);    
    if ($('div#hello').parents(target).length) {
        alert('Your clicked element is having div#hello as parent');
    }
}
$(document).bind('click', fun);
--&gt;
&lt;/script&gt;

&lt;/html&gt;
</code></pre>

<p>I expect only when <code>Child-Of-Hello</code> being clicked, <code>$('div#hello').parents(target).length</code> will return >0.</p>

<p>However, it just happen whenever I click on anywhere.</p>

<p>Is there something wrong with my code?</p>
