D
D
driver4582018-04-21 17:17:41
css
driver458, 2018-04-21 17:17:41

How is a click outside of an element tracked?

For example, there is a dropdown , which has a dropdown list when you click on it.
How to track a click outside of this element to close it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2018-04-21
@driver458

Track the click on the document, and if event.target is not the desired element, then execute the closing code.
UPD: Example https://codepen.io/VladIT4/pen/vjNOKW

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question