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
Asked
Active
Viewed 6,843 times
2
-
1Afaik, 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. – Šime Vidas Jul 25 '11 at 17:10
-
What default behavior specifically do you want to prevent? – Šime Vidas Jul 25 '11 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. – Jul 25 '11 at 18:53
-
Possible duplicate of [preventing a user from changing the state of a radio button](http://stackoverflow.com/questions/7116217/preventing-a-user-from-changing-the-state-of-a-radio-button) – Jessica Aug 18 '16 at 02:35
2 Answers
2
Just return false
.live('click', function (){
return false;
})

ShankarSangoli
- 69,612
- 13
- 93
- 124
-
3I 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. – ShankarSangoli Jul 25 '11 at 17:23