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
6
votes
2 answers

react checkbox: event.preventDefault() breaks onChange function - why?

I have just found a stray event.preventDefault() that was breaking my checkboxes' onChange handler: import { Component } from 'react'; class App extends Component { constructor(props) { super(props) this.state = { accepted: false …
gl03
  • 1,109
  • 12
  • 18
6
votes
1 answer

Javascript stop scrolling on touchmove after scrolling has already started

I have a simple example where a user starts to scroll on a touch screen, and then after one second, I want to disable scrolling. I thought event.preventDefault() would stop the scrolling but it doesn't seem to work after scrolling has already…
user1763510
  • 1,070
  • 1
  • 15
  • 28
6
votes
4 answers

I'm having trouble using the event.preventDefault(); for an ahref on my DOM

I'm having trouble using the event.preventDefault(); for an ahref on my DOM. How do you prevent the url from posting a nofollow delete, as specified by the HTML using JQuery?
JZ.
  • 21,147
  • 32
  • 115
  • 192
6
votes
0 answers

Automate react stopPropagation and preventDefault

Using current versions of react-dom and @material-ui, I need to stopPropagation and/or preventDefault in quite a few places. I've never ran into a problem like in this article and I guess, it can't happen because of how Material-UI works: AFAIK open…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
6
votes
2 answers

Prevent default event for jQuery keydown in Firefox

I have jQuery code which makes an array of focusable elements and binds .keydown for the left and right arrows to tab through them. In Chrome, IE, and Safari beginning with preventDefault() or ending with a return false (which technically I don't…
Brandon
  • 779
  • 5
  • 9
  • 28
6
votes
3 answers

PreventDefault on Blazor input

I have a simple application with an input field that should insert a predefined piece of text as you type. The code I have looks like this: @functions { private int…
Vivendi
  • 20,047
  • 25
  • 121
  • 196
6
votes
4 answers

React - how to trigger preventDefault() before the synthetic event is recycled?

I have the following function within a React component which is run when a link is clicked: onClick(e, { name }) { e.stopPropagation(); const doIt = await checkSomething(); if (doIt) { e.preventDefault(); …
JoeTidee
  • 24,754
  • 25
  • 104
  • 149
6
votes
3 answers

jquery select dropdown ignores keydown event when it's opened?

I'm trying to prevent backspace button to go one page back in every browser. For now I'm using this code: $(document).on("keydown", function (e) { if (e.which === 8 && !$(e.target).is("input, textarea")) { e.preventDefault(); …
Silko
  • 584
  • 1
  • 8
  • 26
6
votes
3 answers

Prevent Default Click button inside anchor

I am using FancyBox --> jQuery Plugin to display an image gallery. Here's a JSFIDDLE that I'm trying to play around with: --> http://jsfiddle.net/CWaHL/238/ I want the user to be able to delete an image so I created a button on top of the…
bagofmilk
  • 1,492
  • 8
  • 34
  • 69
6
votes
1 answer

e.preventDefault() prevents the default behavior, but return false not. Why?

I have the following simple form:
Use return false (if not checked, e.preventDefault() will be used):
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
6
votes
3 answers

jquery: remove the pointer cursor?

Why can't I change the CSS of an a tag with jquery? For instance, html, 1 2 3 4 link 1 and 2 are not clickable so I want to…
Run
  • 54,938
  • 169
  • 450
  • 748
6
votes
2 answers

Combine jQuery preventDefault and required form inputs

Ok, so putting preventDefault on my submit button works to stop form submission. The consequence of this is that it won't tell the user of required fields and just performs the click event on the button. Adding preventDefault to the submit handler…
o_O
  • 5,527
  • 12
  • 52
  • 90
6
votes
1 answer

Prevent JQuery Mobile swipe event over specific element

I am using jquery mobile and I need to prevent swipe event over specific element. Need of doing this is because I am using slider and I don't want the swipe event to be invoked resp. I want it to be prevented when user is manipulating with slider. I…
marek_lani
  • 3,895
  • 4
  • 29
  • 50
6
votes
1 answer

jQuery trigger() and stopPropagation() on keydown event

I am having a difficult time with keydown and stop propagation i do not want my page to refresh, i have tried every which way i can think of, my current code is