1.0.2 • Published 7 years ago
outside-clicky v1.0.2
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);