Skip to content

Instantly share code, notes, and snippets.

@brendanfalkowski
Created January 25, 2014 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendanfalkowski/8611120 to your computer and use it in GitHub Desktop.
Save brendanfalkowski/8611120 to your computer and use it in GitHub Desktop.
Get "data-callback" attribute from markup, check if the function exists, and then call it.
var elem = $('.selector');
elem.on('click', function (e) {
var callbackName = $(this).data('callback');
if ($.isFunction(window[callbackName])) {
window[callbackName].call(this);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment