Find out if radio button checked with JQuery?

645    Asked by Yashraj in Devops , Asked on Jul 1, 2021

I can set a radio button to checked fine, but what I want to do is set up a sort of 'listener' that activates when a certain radio button is checked.

Take, for example, the following code:

$("#element").click(function()

    $('#radio_button').attr("checked", "checked");
});

it adds a checked attribute and all is well, but how would I go about adding an alert. For example, that pops up when the radio button is checked without the help of the click function?

Answered by shivangi Mehta

To check jquery if radio button checked, try using the code given below:

$('#element').click(function() {
   if($('#radio_button').is(':checked')) { alert("it's checked"); }
});

Your Answer

Interviews

Parent Categories