Custom js preventdefault not working

Hello all,

I've got the next question.
i want to prevent that when i press a .h5p-interaction-button in a interactive video that the action will not be excecuted.

This is what i got.

var H5P = H5P || {}; (function ($) { $(document).ready(function () { $(".h5p-interaction-button").click(function(e){ e.preventDefault(); console.log("test"); }); }); })(H5P.jQuery);

Please advise....

Kind regards

otacke's picture

Hi koenmoret!

"The Event interface's preventDefault() method tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be." (Mozilla) It won't stop the custom H5P listeners from doing their job. And you're just adding another listener anyway ...

Since you seem to be relying on jQuery, you could use 

$(".h5p-interaction-button").off('click');

to remove the event -- and then replace it with whatever you have in mind.

Cheers,
Oliver