For example if I have:
window.onmousemove = function()
{
alert(1);
}
document.querySelector(‘div’).onmousemove = function()
{
alert(2);
}
Will “2” always happen before “1” ?
For example if I have:
window.onmousemove = function()
{
alert(1);
}
document.querySelector(‘div’).onmousemove = function()
{
alert(2);
}
Will “2” always happen before “1” ?
Assuming you click on the div then the divs event listener will alert first and then secondly the window alert will occur.
If you didn’t click on the div then you just get the window alert.
You can change that behavior by using ‘capture’ true and the alerts react on the way down to the element.
e.g.
window.addEventListener(
"click",
function () {
alert("You clicked the parent element!");
},
true
);
document.getElementById("child").addEventListener(
"click",
function () {
alert("You clicked the Child element!");
},
true
);
It’s explained here.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.