Last active
September 4, 2020 20:56
-
-
Save pbojinov/ce5328d3cd5623bcd9fc to your computer and use it in GitHub Desktop.
manually bind an event listener for each value that data-action might hold - http://alexkinnee.com/2013/11/binding-js-events-using-data-action-selectors/
This file contains hidden or 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
// Using [data-action=""] selectors instead of class selectors when binding events in JavaScript | |
var actions = { | |
action1: function() {}, | |
action2: function() {} | |
//.... | |
}; | |
$('body').on('click', '[data-action]', function() { | |
var action = $(this).data('action'); | |
if (action in actions) { | |
actions[action].apply(this, arguments); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment