Below is html
<div class="radio_tab"><span>Ad View</span>
<ul>
<li>Ad View</li>
<li>Page View</li>
</ul>
</div>
My javascript is
$("div").not('.radio_tab').click(function(){
alert('hi');
});
and also i tried
$("div:not(.radio_tab)").click(function(){
alert('hi');
});
I am showing dropdown on click of span and it will hide on clicking on span/ul.
But problem is, i want to hide dropdown onclicking outside div.radio_tab.
I appreciate all your comments
Both of those selectors will find all
divs that do not have the classradio_tab, and apply click handlers to them. That’s probably amazingly inefficient, on top of not being what you want to do. The thing it seems like you’re trying to do ($("*:not('div.radio_tab')")) would be even worse.One alternate approach might be to apply a click handler to the body of the document, and test the event’s target to see whether it’s
div.radio_tab, or one of its children. If not, then hide the div and unbind the event handler. Something along these lines (code written here, and not tested!):