🔰default action
browser ⟩ event ⟩ default action
Many events have a default action associated with them.
event handlers are usually called before the default behavior takes place.
call event.preventDefault() to prevent this normal behavior.
// ⭐️ prevent touch screen default actions.
container.addEventListener("touchmove", event => {
event.preventDefault();
}, {passive: false} ); // ⭐️ importantDepending on the browser, some events can’t be intercepted at all. for example:
Chrome:
ctrl+Worcmd+W(close current tab) cannot be handled by JavaScript.
default actions for:
"click" on <input type="submit"> - submit the form.
"input" on <input> - enter the input.
"scroll" on document - the browser scrolls.
HTML ⟩
<input type="submit"> - submit button
Last updated
Was this helpful?