How can I know which radio button is selected via jQuery?
How can I know which radio button is selected via jQuery?
28929-Aug-2023
Updated on 02-Sep-2023
Home / DeveloperSection / Forums / How can I know which radio button is selected via jQuery?
How can I know which radio button is selected via jQuery?
Aryan Kumar
02-Sep-2023Sure, I can help you with that.
To know which radio button is selected via jQuery, you can use the
:checked
selector. The:checked
selector 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
radioButton
variable 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
isChecked
variable will betrue
. If the radio button is not checked, theisChecked
variable 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
radioButtonValue
variable is the value of the selected radio button.