javascript - jQuery 触发器排除 with .not()

标签 javascript jquery html css

所以我想点击 img“tri”来隐藏 div“popu”。但是 img 是 div popu 的子项,所以我尝试了 .not()。它没有用。注意:我也不希望 div“textb”触发隐藏。

HTML

<div id="re" class="column"><div id="s" class="popu"><img class="tri" src="img/whtri.png"/>
    <div class="textb"><center style="font-size:14px;">Item Title</center>
        <span style="font-size:12px;">Description this is an item that is very good and i like it very much! I like 
            <span class="highl">More...</span>
        </span>
        <span style="">
        </span>
    </div>
</div> 

JQuery
$("body").click(function (e) {
 if (!$(e.target).closest(".popu").length.not(".tri")) {
    $("#s").hide(200)
 }
});

任何帮助都会很棒!

最佳答案

你可以使用.parent():

$('img.tri').click(function() {
    $(this).parent().hide();    
});

.closest():

$('img.tri').click(function() {
    $(this).closest('.popu').hide();    
});

Fiddle Demo

关于javascript - jQuery 触发器排除 with .not(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23282461/

相关文章:

javascript - 如何捕捉 stopPropagation 事件

javascript - JavaScript 中的对象标识

javascript - 让窗口在单击触发两个页面重定向后保持焦点

javascript - tr 上的 dblclick 事件不起作用

html - 视频元素在 html 中并不完美

Javascript 代码在 Node 中不起作用?

javascript - Turbolinks 5.0 和 Facebook SDK

JavaScript 异步调用

html - Video.js - 防止点击播放功能

html - Angular 5 @Input宽度并应用于div