Toggle CSS Class When Clicking Outside Of An Element – clickout

Category: Javascript | June 12, 2019
Author: rainjeck
Views Total: 119
Official Page: Go to website
Last Update: June 12, 2019
License: MIT

Preview:

Toggle CSS Class When Clicking Outside Of An Element – clickout

Description:

clickout is a pure JS library which detects the Click Outside event and removes a CSS class from a given element when you click outside of the element.

See also:

How to use it:

Download and insert the JavaScript file clickout.js into the document.

<script src="/path/to/clickout.js"></script>

Initialize the library on the target element and specify the CSS class to remove when clicking outside.

<div class="is-active js-clickout">
  Element
</div>
var clickout = new clickOut.default({
    className: '.js-clickout',
    activeClass: 'is-active', // class to remove
});

Execute a callback function after you click outside of the element.

var clickout = new clickOut.default({
    after: function(elements) {
      console.log(elements);
    }
});

You Might Be Interested In:


Leave a Reply