Location Location e.preventDefault ()

I use preventDefault() in my jquery functions to prevent submit buttons from being sent in the usual way. There is a value of preventDefault() . Should it be the first or maybe the last in a function?

+4
source share
2 answers

No, it doesnโ€™t matter: https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault

This is different from returning false , because when you return, everything else in the function is abandoned.

As stated in the MDC link above:

Calling preventDefault during any stage of the event flow cancels the event, which means that any default action normally taken by the implementation as a result of the event will not occur.

+8
source

It doesnโ€™t matter, but I would like to express it first. The alleged behavior is clearly visible when you quickly look at the code when it is at the top.

+3
source

Source: https://habr.com/ru/post/1332586/


All Articles