What does Event.target mean === Document.documentElement

Asked

Viewed 192 times

0

At the bottom of the code "Event.target === Document.documentElement" what exactly this does?

(This script as a whole makes that if I click on a place outside mobile menu, it closes, but this excerpt from the script I did not understand exactly...)

inserir a descrição da imagem aqui

1 answer

2


It means whether the element that triggered the event click (event.target) was the very document (document.documentElement). That is, if you click anywhere empty on the page where there is no element of body (div, a, input etc.), will satisfy the condition of if.

     operador de igualdade
       por valor e tipo
              ↑
event.target === document.documentElement
     ↓                   ↓
elemento que          <html>...</html>
disparou o evento

Now, the same could be done only with document.onclick instead of document.documentElement.onclick. The difference is that the document is an object that represents the whole document, while documentElement is an object representing the tag html page.

  • This way, if I create a modal (for example) and click out of it, this condition will be valid to remove the modal? interesting

  • No. You would have to use another code. Something like this answer: https://answall.com/a/375537/8063

Browser other questions tagged

You are not signed in. Login or sign up in order to post.