Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9281405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:06:45+00:00 2026-06-18T18:06:45+00:00

When I don’t want to execute the default action that is associated with the

  • 0

When I don’t want to execute the default action that is associated with the event, I use

function listener(e){
    if(e.preventDefault) e.preventDefault();
    /* Other code */
}

But I have just learnt that events have the boolean cancelable. Then, should I use this code instead?

function listener(e){
    if(e.cancelable) e.preventDefault();
    /* Other code */
}

I wonder:

  • If event.preventDefault is true, does it really mean that the event is cancelable? Maybe if it isn’t cancelable, that attribute is defined (and true), but it isn’t a function; or it’s a function but if I call it it throws an error.
  • Does all browsers (IE, I’m looking at you) support event.cancelable? Is there a browser which has the method event.preventDefault but doesn’t have event.cancelable; or has the method event.cancelable but doesn’t have event.preventDefault; or that event.cancelable doesn’t always imply that event.preventDefault is defined and it’s a function and it doesn’t throw errors?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T18:06:46+00:00Added an answer on June 18, 2026 at 6:06 pm

    This:

    if (e.preventDefault)
    

    merely means that the event object has a property called “preventDefault”. It’s a browser feature test, because old versions of IE didn’t have that. Instead, in IE you set the property “returnValue” on the event object to false.

    Thus, the reason you test for “preventDefault” is to see whether that function is available; if the property is null, you obviously can’t make the function call. So when you want to prevent the default action, your code should look like this:

    if (e.preventDefault)
      e.preventDefault();
    else
      e.returnValue = false;
    

    If the “cancelable” flag is false, then that means you cannot prevent default behavior. The “preventDefault” function is still there (if it normally would be), but calls to it are ignored for non-cancelable events. There’s no need to check the flag at all, really; it’s a static characteristic of the particular type of event, usually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't they both have to convert to machine code at some point to execute
Don't understand this simple code: def main(): print (This program illustrates a chaotic function)
Don't be scared of the extensive code. The problem is general. I just provided
I don't know why, but this code worked for me a month ago... maybe
Don't think that I'm mad, I understand how php works! That being said. I
Don't know if I'm using the not selector incorrectly but I want everything clicked
Don't be afraid to use any technical jargon or low-level explanations for things, please.
Don't be frightened, its a very basic code. Just wanted to check with you
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know where else to ask, but from one day to the other my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.