javascript - How can I toggle a radio button's checked state with jQuery? -
as can seen here, i've got html:
<input type="radio" id="radbtnemp" >rad btn</input>
...and jquery:
$('#radbtnemp').click(function () { alert("radbtnemp clicked"); });
the alert does display when click radio button; however, clicking radio button second time not toggle state unchecked. how can in jquery?
i want able respond state (or similar):
if ($('#radbtnemp').attr('checked', true)) { // stuff } else { // other stuff }
...but if radiobutton never checked/false, doesn't work.
the radio buttons cannot checked , unchecked..
for need use checkboxes:
html:
<input type = "checkbox" id = "mycheckbox">i checkbox</input>
jquery:
$('#mycheckbox').on('click', function() { if ($('#mycheckbox').is(':checked')) { // code } else { // code } })
hope helps
Comments
Post a Comment