Exclude click event based on condition?

前端 未结 5 1269
悲&欢浪女
悲&欢浪女 2021-02-14 04:38

I\'m trying to set conditions on a jQuery event. I have an input element and a div. I want to detect a click anywhere on the page and to execute that method but only if the clic

5条回答
  •  情深已故
    2021-02-14 05:02

    Example to exclude specific elements using a wildcard:

    $("#mydiv li").click(function(e){
    
            var Target = new String(e.target.id);
    
            // prevent action when a element with id containing 'img_' is clicked
            if( !Target.match(/img_/ )) {
                // do something
            }
    
    });
    

提交回复
热议问题