问题
does anyone know if css position:relative; can mess up the function
$('body').not($('.theDIV')).click(function(){
alert('');
});
or the problem is somewhere else?
what is happening is i have a that appears on click of a button and i want it to hide() when i click anywhere on the body, except the div itself. HTML
<ul class='messages'> //these are made dynamically. should i use each() to go through all the elements?
<li>
<div class='theDIV'></div>
<input type='button'>
</li>
<li>
<div class='theDIV'></div>
<input type='button'>
</li>
<li>
<div class='theDIV'></div>
<input type='button'>
</li>
</ul>
sorry if i wasnt clear the first time
回答1:
You could do
$('body').click(function(e){
if(! $(e.target).hasClass('theDIV')){
alert('clicked on something that has not the class theDIV');
}
});
来源:https://stackoverflow.com/questions/9711134/click-on-body-except-some-other-tag-not-working