Sem*_*iev 2 jquery except document-body
有没有人知道如果css位置:相对; 可以弄乱这个功能
$('body').not($('.theDIV')).click(function(){
alert('');
});
Run Code Online (Sandbox Code Playgroud)
或者问题出在别的什么地方?
发生的事情是我有一个出现在点击一个按钮,我希望它隐藏()当我点击身体的任何地方,除了div本身.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>
Run Code Online (Sandbox Code Playgroud)
对不起,如果我第一次不清楚
你可以做到
$('body').click(function(e){
if(! $(e.target).hasClass('theDIV')){
alert('clicked on something that has not the class theDIV');
}
});
Run Code Online (Sandbox Code Playgroud)