Detect click inside/outside of element with single event handler

后端 未结 10 1695
南笙
南笙 2020-12-04 15:48

Suppose I have one div in my page. how to detect the user click on div content or outside of div content through JavaScript or JQuery. please help with small code snippet. t

10条回答
  •  無奈伤痛
    2020-12-04 15:52

    If you want to add a click listener in chrome console, use this

    document.querySelectorAll("label")[6].parentElement.onclick = () => {console.log('label clicked');}
    

提交回复
热议问题