Reputation: 792
I'm using a platform that generates pages with minified js files (Madcap Flare), and I need to add some code to a click event. I tried the following:
$('body').on('click', 'a', function(e) {
alert( 11111111111 );
})
It triggers in some places, but not where I need it to, making me think somewhere there's a preventDefault()
instruction.
Is there some way of getting around it?
I read about event.isDefaultPrevented()
, but is it possible to get that function to work outside a triggered function? I mean if you are inside the trigger, then it wasn't prevented, and if it is prevented, how to you meet the isDefaultPrevented()
instruction?
Upvotes: 2
Views: 395
Reputation: 11813
... if you are inside the trigger, then it wasn't prevented, and if it is prevented, how to you meet the isDefaultPrevented() instruction?
You may want to use it in another event binding function:
// Your original code
$('body').on('click', 'a', function(e) {
alert( 11111111111 );
})
// Somewhere else in your code
$('body').on('click', 'a.some-class', function(e) {
if(e.isDefaultPrevented()){
console.log('Yeap, some other function has called e.preventDefault()');
}
});
Is there some way of getting around it?
Yeap, trigger a new event. You may want to create a new event object to do that.
Upvotes: 3