Detect click outside div using javascript

后端 未结 7 1880
無奈伤痛
無奈伤痛 2020-12-02 13:10

I\'d like to detect a click inside or outside a div area. The tricky part is that the div will contain other elements and if one of the elements inside the div is clicked, i

7条回答
  •  失恋的感觉
    2020-12-02 13:37

    you can apply if check for that inside your click event

    if(event.target.parentElement.id == 'yourID')
    

提交回复
热议问题