Reputation: 22167
HTML :
<label><input type="radio" name="type">Stackoverflow</label>
<label><input type="radio" name="type">Google</label>
jQuery :
$("input:radio").eq(0).attr('checked',true); // Set 1st input checked by jQuery
$("input:radio:not(:checked)").on("click", function(){
console.log("yes!");
});
Demo : http://jsbin.com/onayec/1/edit
Look like HTML attr checked="checked"
doesn't remove when click another input:radio
I just want to check if not click input:radio
who checked
Upvotes: 2
Views: 365
Reputation: 144689
Events are bound to elements not to their properties, ie, when you select an element, the handler is bound to that element, the handler is not updated when properties are changed, if you want to bind a click handler to input elements that are not checked
you should use event delegation.
However, it's not a good example for radio/checkbox input elements, what you are after is a simplechange
event handler. The point was showing how events are bound to elements.
Upvotes: 1
Reputation: 73906
You can also try this:
$('input:radio').click(function () {
if ($(this).is(':checked')) {
// do something
alert('Ckecked');
}
});
Upvotes: 1