How can I know which radio button is selected via jQuery?
How can I know which radio button is selected via jQuery?
568
29-Aug-2023
Updated on 02-Sep-2023
Aryan Kumar
02-Sep-2023Sure, I can help you with that.
To know which radio button is selected via jQuery, you can use the
:checkedselector. The:checkedselector selects all radio buttons that are checked.The following code shows how to know which radio button is selected via jQuery:
In this code, the
radioButtonvariable is the jQuery object for the radio button element. Theis(":checked")method is used to check if the radio button is checked.If the radio button is checked, the
isCheckedvariable will betrue. If the radio button is not checked, theisCheckedvariable will befalse.You can also use the
val()method to get the value of the selected radio button. The following code shows how to get the value of the selected radio button:In this code, the
radioButtonValuevariable is the value of the selected radio button.