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
751
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?
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
: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
Event bubbling, just event.target
There are siblings that may be able to solve this...