I am creating a class:
var MyClass;
(function($) {
MyClass = new function() {
$('a').off('click');
$('a').on( 'click', function(event) {
event.preventDefault();
});
};
})(jQuery);
When clicking on a link, a full request is still being issued.
When pasting ...
$('a').on( 'click', function(event) {
event.preventDefault();
});
... in my console and retrying, everything works as expected.
Is it possible that I am not able to initialize an event listener from within a class definition. If so, how would I initialize my event listener then?
$(document).ready()or you need to use event delegation to bind to dynamically-created elements.