Window.document.addEventListener vs window.addEventListener

window.document.addEventListener = function(event) {...}

window.addEventListener = function(event) {...}

What is the difference between these two lines of code? I get that this window and the document object are two different objects with different properties, and this site provides a good visual guide to the difference. However, I see no difference between what these two lines of code do.

To clarify: what is the difference in doing something like this: window.addEventListener('mousemove', function (event) {...}); and do something like this window.document.addEventListener('mousemove', function (event) {...});?

+4
source share
1 answer

addEventListener DOM, window. bubble , , .

addEventListener .

, ( -) , . , , :

window.addEventListener('click', handler);
document.querySelector('button', handler);

, .

+2

Source: https://habr.com/ru/post/1611487/


All Articles