Cle*_*lem 1 javascript jquery parent
我如何检查,如果点击的元素不是某个特定DIV元素的子元素?
$("body").click(function(e) {
if(e NOT child of $('#someDiv')) alert(1);
});
Run Code Online (Sandbox Code Playgroud)
if ($(e.target).parent('#someDiv').length == 0) {
...
}
Run Code Online (Sandbox Code Playgroud)
或者,你是说("不是e的祖先"):
if ($(e.target).closest('#someDiv').length == 0) {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
102 次 |
| 最近记录: |