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:

  1. in other situations can use preventdefault()?

  2. 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

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -