Skip to content

Instantly share code, notes, and snippets.

@pbojinov
Last active September 4, 2020 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pbojinov/ce5328d3cd5623bcd9fc to your computer and use it in GitHub Desktop.
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/
// 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