Reputation: 1271
I am trying to figure out why my page doesn't fire the radio button change event.
Here's the script I have for it, it's supposed to show a div once the radio button is checked.
$("input[id$='radio1']").change(function () {
if ($("input[id$=radio1]").is(':checked')) {
$('#div1').removeClass('hidden');
}
});
what's wrong with this code?
Upvotes: 0
Views: 1563
Reputation: 148714
$("input[id$='radio1']").change(function () {
if ($(this).is(":checked")) {
$("#div1").removeClass("hidden");
}
});
Upvotes: 5
Reputation: 78570
$("input[id$='radio1']").change(function () {
if ($(this).is(':checked')) {
$('#div1').removeClass('hidden');
}
});
You should use the this
object in your function.
Upvotes: 3
Reputation: 6009
try asking in this way if the radio is checked.
if(document.getElementById('radio1').checked) {
$('#div1').removeClass('hidden');
}
Upvotes: 0
Reputation: 14421
You need to use the this
keyword inside the function, instead of asking jQuery to search for elements matching the selector again.
$("input[id$='radio1']").change(function () {
if ($(this).is(':checked')) {
$('#div1').removeClass('hidden');
}
});
Upvotes: 1