npm.io
1.0.2 • Published 9 years ago

outside-clicky

Licence
ISC
Version
1.0.2
Deps
0
Vulns
0
Weekly
0

OutsideClicky

Listen for clicks outside of an element

Install

npm install outside-clicky --save

Usage

Initializing OutsideClicky
// Require OutsideClicky
const OutsideClicky = require('outside-clicky');
    
// Get the target element 
let myDiv = document.querySelector('.js-myDiv');
    
// Create a callback function that runs when you click outside of your target element
let myCallbackFunction = function () {
	console.log('You clicked outside myDiv');
};
    
// Initialize OutsideClicky
let myOC = new OutsideClicky();
Binding the listener
myOC.bind(myDiv, myCallbackFunction);
Unbinding the listener
myOC.unbind();
Automatically unbind after outside click
myOC.bind(myDiv, myCallbackFunction, true);