Questions tagged [preventdefault]

Javascript event method to cancel the event if it is cancelable, without stopping further propagation of the event.

Javascript event method to cancel the event if it is cancelable, without stopping further propagation of the event.

960 questions
1104
votes
9 answers

What's the difference between event.stopPropagation and event.preventDefault?

They seem to be doing the same thing... Is one modern and one old? Or are they supported by different browsers? When I handle events myself (without framework) I just always check for both and execute both if present. (I also return false, but I…
Rudie
  • 52,220
  • 42
  • 131
  • 173
349
votes
28 answers

How to preventDefault on anchor tags?

Let's say I have an anchor tag such as Click How can I prevent the browser from navigating to # in AngularJS ?
Micael
  • 6,950
  • 6
  • 25
  • 28
246
votes
20 answers

What is the opposite of evt.preventDefault();

Once I've fired an evt.preventDefault(), how can I resume default actions again?
Bryan
  • 2,461
  • 2
  • 15
  • 3
207
votes
11 answers

event.preventDefault() function not working in IE

Following is my JavaScript (mootools) code: $('orderNowForm').addEvent('submit', function (event) { event.preventDefault(); allFilled = false; $$(".required").each(function (inp) { if (inp.getValue() != '') { …
sv_in
  • 13,929
  • 9
  • 34
  • 55
174
votes
13 answers

Prevent Default on Form Submit jQuery

What's wrong with this? HTML:
djreed
  • 2,673
  • 4
  • 22
  • 21
132
votes
20 answers

How to unbind a listener that is calling event.preventDefault() (using jQuery)?

jquery toggle calls preventDefault() by default, so the defaults don't work. you can't click a checkbox, you cant click a link etc etc is it possible to restore the default handler?
user188049
114
votes
15 answers

React onClick and preventDefault() link refresh/redirect?

I'm rendering a link with react: render: -> `upvote` Then, above I have the upvote function: upvote: -> // do stuff (ajax) Before link I had span in that place but I need to switch to link and…
Wordpressor
  • 7,173
  • 23
  • 69
  • 108
98
votes
4 answers

event.preventDefault() vs. return false (no jQuery)

I wondered if event.preventDefault() and return false were the same. I have done some tests, and it seems that If the event handler is added using old model, for example elem.onclick = function(){ return false; }; Then, return false prevents…
Oriol
  • 274,082
  • 63
  • 437
  • 513
91
votes
6 answers

Bootstrap 3 - disable navbar collapse

This is my simple navbar:
84
votes
1 answer

When to use PreventDefault( ) vs Return false?

Firstly, in JavaScript's event model, you will come across a concept called as event bubbling (which makes an event to propagate from child element to a parent element). In order to avoid such kind of bubbling effect, many developers use an event…
Mike
  • 841
  • 1
  • 7
  • 5
54
votes
5 answers

Stop form from submitting , Using Jquery

I'm trying to stop my form from submitting if a validation fails. I tried following this previous post but I doesn't work for me. What am I missing?
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188
50
votes
4 answers

Ctrl+S preventDefault in Chrome

I Want to catch Ctrl+S in Chrome, and prevent the default browser behavior to save the page. How? (Just posting the question & answer as I was after this for a pretty long time and didn't find a solution)
zupa
  • 12,809
  • 5
  • 40
  • 39
38
votes
1 answer

Vuejs - automatic event.preventDefault()

right now, I need to add event.preventDefault() to all of my click events in my Vue.js buttons:

methods: { someAction (e) { e.preventDefault() …
John Grayson
  • 1,378
  • 3
  • 17
  • 30
36
votes
3 answers

Can't prevent `touchmove` from scrolling window on iOS

We are trying to scroll an element on our iOS web app while preventing the window itself from scrolling. We are capturing the touchmove event on the window, scrolling the element programmatically and (trying to) prevent the window itself from scroll…
Matthew Gertner
  • 4,487
  • 2
  • 32
  • 54
31
votes
3 answers

Prevent href from opening link but still execute other bind events

I want to prevent links from opening pages. So I have written this : $("a").click(function(e) { e.preventDefault() } which is great! But this blocks my other event : $(".toolbar a").click(function(e) { ...action... } Sure I can add my…
Benoit R
  • 338
  • 1
  • 3
  • 8
1
2 3
63 64