2

I need to stop prevent default behavior of radio button to check if it checked before I click it or not, I'm using .live('click', function (){}) because the HTML added to DOM with AJAX

4
  • 1
    Afaik, it is not possible to prevent default behavior from within a live handler. By the time it is run, the event already bubbled up and the default behavior executed. Jul 25, 2011 at 17:10
  • What default behavior specifically do you want to prevent? Jul 25, 2011 at 17:31
  • You can disable the radio button and/or invert the checked property upon clicking. Ex: radio.checked = !radio.checked;. Afterwards, you can invert the checked property back if a certain criteria is met.
    – user1385191
    Jul 25, 2011 at 18:53
  • Possible duplicate of preventing a user from changing the state of a radio button
    – Jessica
    Aug 18, 2016 at 2:35

2 Answers 2

6

Just return false; from the handler.

0
2

Just return false

.live('click', function (){
        return false;
    }) 
1
  • 3
    I think it will not work using live. You have to attach the event for each radio button on the page. Live use event bubling mechanism so before we return false the button is already checked. Jul 25, 2011 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.