Categories
JavaScript Answers

How to Listen to the mouseup Event Outside of an HTML Element?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *