Last active
August 29, 2015 14:01
-
-
Save cferdinandi/4e7ad4da839fefa33c05 to your computer and use it in GitHub Desktop.
A simple method to set and remove event listeners for dynamically generated content.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Event selector defaults | |
var toggles; // Toggle nodes list | |
var eventListeners = []; //Listeners array | |
// Whenever a toggle is clicked, run the function | |
toggles = document.querySelectorAll('[data-collapse]'); // Get all collapse toggles | |
forEach(toggles, function (toggle, index) { | |
eventListeners[index] = exports.FUNCTION.bind( null, VARIABLES ); | |
toggle.addEventListener('click', eventListeners[index], false); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment