Sometimes, we want to listen to the mouseup
event outside of an HTML element.
In this article, we’ll look at how to listen to the mouseup
event outside of an HTML element.
Listen to the mouseup Event Outside of an HTML Element
To listen to the mouseup
event outside of an HTML element, we can call window.addEventListener
method to listen to the mouseup
event on the whole browser tab or window.
For instance, we can write:
window.addEventListener('mouseup', (event) => {
console.log('mouse up')
})
We call window.addEventListener
with 'mouseup'
to listen to the mouseup
event on the whole browser window.
Now when we lift the mouse button anywhere in the browser window, we see 'mouse up'
logged.
Conclusion
To listen to the mouseup
event outside of an HTML element, we can call window.addEventListener
method to listen to the mouseup
event on the whole browser tab or window.