I use on() JQuery function and preventDefault() for prevent anchor default action. I can not understand off() JQuery function. can I use off('click') instead of:
$('.anchor').on('click', function(e) {
e.preventDefault();
});
I mean, can I use this for prevent default action of anchor?
$('.anchor').off('click');
No, as per the documentation of .off():
The
.off()method removes event handlers that were attached with.on().
So off() only removes handlers that were added by jQuery. But default handlers, e.g. on a link or on a submit button, must be prevented by preventDefault().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With