I'd like to get the value
of the checked checkbox that has the radioListMode
class:
<label class="btn btn-secondary active">
<input type="radio" class="radioListMode" value="cards" checked>Cards
</label>
<label class="btn btn-secondary">
<input type="radio" class="radioListMode" value="pins">Pins
</label>
From this previous question, this is what I have tried and it is undefined
:
console.log($('input[class="radioListMode"]:checked').value);
I do not wish to add a name
because the value of this checkbox is only used for layout selection, not any data input.
I'd like to get the value
of the checked checkbox that has the radioListMode
class:
<label class="btn btn-secondary active">
<input type="radio" class="radioListMode" value="cards" checked>Cards
</label>
<label class="btn btn-secondary">
<input type="radio" class="radioListMode" value="pins">Pins
</label>
From this previous question, this is what I have tried and it is undefined
:
console.log($('input[class="radioListMode"]:checked').value);
I do not wish to add a name
because the value of this checkbox is only used for layout selection, not any data input.
- Have you tried $('input.class="radioListMode"]:checked').val() – progrAmmar Commented Feb 23, 2016 at 2:27
- I don't understand why you wouldn't add an ID. The extra amount of data sent would not make much of a difference in bandwidth costs unless you were processing billions (with a b) of users a month. – Jon Commented Feb 23, 2016 at 2:27
4 Answers
Reset to default 4Since you seem to be using jQuery, stick with it:
$('input.radioListMode:checked').val();
Use .val()
property
$('input[class="radioListMode"]:checked').val()
.value
is not a jQuery function, instead use .val()
like following :
console.log($('input[class="radioListMode"]:checked').val());
$(".yourClassName:checkbox:checked").each(function() {
console.log($(this).attr("id"));
});