javascript - How and when to use preventDefault()? -
from tutorial, said:
preventdefault();
1 thing: stops browsers default behaviour.
i searched online examples of preventdefault()
, can see in 2 situations (link, form) use preventdefault()
: prevent submit button submitting form , prevent link following url.
so, question is:
in other situations can use
preventdefault()
?how find out browsers default behaviour? e.g. if click button, browsers default behaviour?
1.in else situation can use preventdefault()?
actually type of event, can stop default behavior preventdefault();
not submit buttons, keypresses, scrolling events, name , can prevent happening. or if you'd add own logic default behavior, think of logging event or of choice.
2.how find out browsers default behaviour? e.g. if click button, browsers default behaviour?
what mean this? default behavior kind of implied. when click button, onclick event fires. when click submit button, form submitted. when windows scrolls, onscroll event fires.
Comments
Post a Comment