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?
$("input[id$='radio1']").change(function () {
if ($(this).is(":checked")) {
$("#div1").removeClass("hidden");
}
});
$("input[id$='radio1']").change(function () {
if ($(this).is(':checked')) {
$('#div1').removeClass('hidden');
}
});
You should use the this
object in your function.
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');
}
});
try asking in this way if the radio is checked.
if(document.getElementById('radio1').checked) {
$('#div1').removeClass('hidden');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.