Detecting Click Outside Of A DOM Element – when-clicked-outside

Category: Javascript | September 5, 2020
Author: 3stacks
Views Total: 152 views
Official Page: Go to website
Last Update: September 5, 2020
License: MIT


Detecting Click Outside Of A DOM Element – when-clicked-outside


when-clicked-outside is a pure JavaScript library which detects and execute a callback function when clicking outside of a specific DOM element.

How to use it:

Install the when-clicked-outside and import it into your project.

# Yarn
$ yarn add @lukeboyle/when-clicked-outside

$ npm install @lukeboyle/when-clicked-outside
import whenClickedOutside from '@lukeboyle/when-clicked-outside';

Or include the compiled JavaScript file ‘when-clicked-outside.js’ on the web page.

<script src="when-clicked-outside.js"></script>

Initialize the whenClickedOutside and specify the DOM element you want to keep track of the click events.

<div id="element">
whenClickedOutside('#element', whenClickedOutsideCallback);

Execute a function as you click outside of the element.

function whenClickedOutsideCallback(event) {



  • refactor: convert to ts


  • Refactor

You Might Be Interested In:

Leave a Reply