Exclude click event based on condition?

前端 未结 5 1249
悲&欢浪女
悲&欢浪女 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 04:57

    Something like this should work.

    $('body').click(function(event){ // body click
        var $target = $(event.target); // click target
        if($target.is('#mydiv, #myinput')) { // click target is div or input
            $target.click(); // click div or input
        }
    });
    

提交回复
热议问题