Skip to content

A simple easy to use script to determine whenever the user clicks outside a selected element.

License

Notifications You must be signed in to change notification settings

cvaize/vanilla-click-outside

 
 

Repository files navigation

VanillaClickOutside 🍦

Demo

A simple, small (565 bytes) and easy to use function to detect if the user clicks outside an element.

Installation

npm install vanilla-click-outside

How to use

UMD

<head>
  <link rel="stylesheet" href="./path/to/vanilla-click-outside.umd.css" />
  <script defer src="./path/to/vanilla-click-outside.umd.js"></script>
</head>
<body>
  <div id="target">
    <section></section>
  </div>
</body>

JavaScript:

const target = document.getElementById('target')
vanillaClickOutside(target, (type, event) => {
  console.log(type, event)
})

CommonJS

import { vanillaClickOutside } from 'vanilla-click-outside'

const target = document.getElementById('target')
vanillaClickOutside(target, (type, event) => {
  console.log(type, event)
})

Options

Option Default Type Description
removeListener true boolean If you want to handle removeEventListener by yourself.

About

A simple easy to use script to determine whenever the user clicks outside a selected element.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%