javascript - How to write jquery to exclude an element and its sub-elements and select all other elements
伊谢尔伦
伊谢尔伦 2017-05-19 10:44:06
0
6
781

As shown in the picture, only clicking on the yellow and blue areas will execute the function. Clicking on the red area and the green sub-elements within the red will not execute the function. How to write it with jquery?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(6)
淡淡烟草味
$('#yellow','#blue').click(function(){
    // dosomething...
})
世界只因有你

:not()

http://www.w3school.com.cn/cs...

为情所困

var _sel = true;
$(".red",".green").click(function{
_sel = false;
})
$('.yellow','.blue').click(function( ){
_sel = true;
})
if(_sel == true){
//Execute function
}
or

There is a public class to execute the function
$(class).click(funciton(){

    //执行函数

})

Red and green do not have this class

迷茫

Finally, I first wrote a function that is executed when all elements are clicked. In the function, it is judged whether the className of the clicked element and the parent element of the element have the className. If it is true, the following content will not be executed

$(document).click(function(){
  if(!(event.target.className==="red"||event.target.parents().hasClass('red')){
    //执行相关操作
  }
}
阿神

Event bubbling, just event.target

PHPzhong

There are siblings that may be able to solve this...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template