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

  • Home
  • SEARCH
  • 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 7793005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:21:02+00:00 2026-06-01T22:21:02+00:00

See this jsFiddle: http://jsfiddle.net/nathanfriend/vAcpc/9/ It seems that the preventDefault() method doesn’t prevent the clicked

  • 0

See this jsFiddle:

http://jsfiddle.net/nathanfriend/vAcpc/9/

It seems that the preventDefault() method doesn’t prevent the clicked radio button from toggling (notice that the message always says “This radio button was checked”, regardless of its prior state). However, after the onclick() method finishes, the radio buttons snap back to their initial states (except for the very first time a radio button is selected).

It seems like preventDefault() works not by actually preventing the radio button from being checked, but rather by just returning the set of buttons to their prior state. Can anyone explain this behavior? I’d like to be able to completely prevent the radio button from ever being toggled – this way I could accurately check to see if the radio button was checked inside its onclick() method. Any ideas?

  • 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-01T22:21:04+00:00Added an answer on June 1, 2026 at 10:21 pm

    Actually a mousedown event will get fired first and check your radio button. You can easily verify this by holding the mouse button on a radio button. However, almost all GUI elements only get executed or changed if both mousedown and mouseup are fired and successfully run.

    See this example (demo):

    $(function() {
        $('[name="test"]').each(function() {
             $(this).mousedown(function(e) {
                e.preventDefault();
                if ($(this).is(':checked')) {
                    alert('This radio button was checked in mousedown');                
                } else {
                    alert('This radio button was not checked in mousedown');
                }                    
            });
            $(this).click(function(e) {
                e.preventDefault();
                if ($(this).is(':checked')) {
                    alert('This radio button was checked');
                } else {
                    alert('This radio button was not checked');
                }                    
            });
        });           
    });
    

    As you can see the mousedown gets fired first, and it will alert ‘This radio button was not checked in mousedown’. The click event is prevented because the actually mouseup event gets canceled by the nasty alert. However, if you use console.log you’ll notice that click is still executed and the radio button is still checked virtually.

    However, if you check for active radio buttons you’ll notice that none is active. The behavior of click element is sometimes irritating, but e.preventDefault() will do it’s job, don’t worry.

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

Sidebar

Related Questions

Please see this: http://jsfiddle.net/uNbYu/1/ If you click submit, the button doesn't do anything, but
If you look at this JSfiddle http://jsfiddle.net/littlesandra88/G3N4m/ you will see that I have input
See this jsfiddle for example: http://jsfiddle.net/FrJRA/1/ and note that the inner span's border overlaps
See this example: http://jsfiddle.net/EwtaC/1/ The images are styled via display:inline-block. I understand that whitespace
You can see the example here: http://jsfiddle.net/8EHED/8/ This is a tricky problem because I
This is my code: http://jsfiddle.net/WCP5f/2/ If you open it with Chrome, you will see
http://jsfiddle.net/YaMhn/8/ ^^^^Take a look and see if you can help solve this Ok so
I'm running this code in Firefox 11 on Windows 7. (See http://jsfiddle.net/QStkd/ ). $('<div><input
See this fiddle: http://jsfiddle.net/uqJHf/ I have set the first column to show up with
please see this example http://jsfiddle.net/7trcV/ what I'm trying to achieve is ability to put

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.