Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out whether radio button is checked with JQuery?

I can set a radio button to checked fine, but what I want to do is setup 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?

like image 883
Keith Donegan Avatar asked Feb 16 '10 11:02

Keith Donegan


People also ask

How do you check if radio button is checked or not?

To find the selected radio button, you follow these steps: Select all radio buttons by using a DOM method such as querySelectorAll() method. Get the checked property of the radio button. If the checked property is true , the radio button is checked; otherwise, it is unchecked.

How check if checkbox is checked jQuery?

To check whether a Checkbox has been checked, in jQuery, you can simply select the element, get its underlying object, instead of the jQuery object ( [0] ) and use the built-in checked property: let isChecked = $('#takenBefore')[0]. checked console. log(isChecked);


1 Answers

$('#element').click(function() {    if($('#radio_button').is(':checked')) { alert("it's checked"); } }); 
like image 138
David Hedlund Avatar answered Sep 29 '22 22:09

David Hedlund