I'm trying to get the radio buttons that has a certain class that is selected.
Getting the radio buttons of that class comes with
$("input:radio.someClass");
I thought that this would work to get the selected radio button -
$("input:radio.someClass:selected");
But that returns empty - what am I doing wrong?
Using Input Radio checked property: The Input Radio checked property is used to return the checked status of an Input Radio Button. Use document. getElementById('id'). checked method to check whether the element with selected id is check or not.
You can check a radio button by default by adding the checked HTML attribute to the <input> element. You can disable a radio button by adding the disabled HTML attribute to both the <label> and the <input> .
We can check the status of a radio button by using the :checked jQuery selector together with the jQuery function is . For example: $('#el').is(':checked') . It is exactly the same method we use to check when a checkbox is checked using jQuery.
To avoid having multiple radio buttons selected use the same name attribute. Radio buttons are normally presented in radio groups. Only one radio button in a group can be selected at the same time. The radio group must share the same name (the value of the name attribute) to be treated as a group.
Use this script
$("input:radio.classNmae:checked").val();
According to JQuery documentation.
The :selected
selector works for option elements. It does not work for checkboxes or radio inputs;
Try:
$("input:radio.someClass:checked");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With