单击正文,但其他一些标签不起作用 [英] click on body except some other tag not working

查看:88
本文介绍了单击正文,但其他一些标签不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道css position:relative是否;会弄乱功能

does anyone know if css position:relative; can mess up the function

    $('body').not($('.theDIV')).click(function(){
    alert('');

    });

还是问题出在其他地方?

or the problem is somewhere else?

发生的事情是我单击按钮时出现了,并且我希望在单击除div本身以外的任何位置时都将其隐藏(). HTML

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

推荐答案

您可以做到

$('body').click(function(e){
   if(! $(e.target).hasClass('theDIV')){
     alert('clicked on something that has not the class theDIV');
   }

});

这篇关于单击正文,但其他一些标签不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆