Reputation: 605
Is it possible to disable standard action being performed while clicking radio button? (without "disable" attr)
So when i click particular radio button, nothing happens. Tried .unbind('click') but doesnt seem to work.
Ty in advance for help
Upvotes: 2
Views: 6818
Reputation: 957
Actually, the first time you click the radio, the checked property is set and hence it shows as checked in browser ( for the firtst time ).
So this piece of code will solve the issue
[I am using jquery library]
$('input:radio').click(function(){
$(this).prop('checked',false);
e.preventDefault();
return false;
});
Upvotes: 1
Reputation: 262919
You can use the preventDefault() method exposed by the event
object:
$("input:radio").click(function(e) {
e.preventDefault();
});
EDIT: Unfortunately, this does not seem to prevent the browser from checking the radio button that is clicked first (jsFiddle is in "emergency read-only" mode, so I cannot post a demo right now).
Upvotes: 4
Reputation: 549
You need to use event.disableDefault in the function you give to jQuery click.
$("#my_element").click(
function(event) {
event.preventDefault();
// the rest of your code goes here
}
);
Upvotes: 0
Reputation: 2405
You can try this, this will stop propagation :
$("#my-radio-btn").live("click", function(e){
e.preventDefault();
});
Upvotes: 1
Reputation: 69905
Just try this.
$('input:radio').click(function(e){
e.preventDefault();
});
Upvotes: 1
Reputation: 66663
This should work:
$('#myradio').click(function(e) {
e.preventDefault();
return false;
});
Upvotes: 1