I'm trying to get the text
of the labels that belong to checked
radio buttons, but don't seem quite to be able to.
$(document).ready(function(){
$("body").on("click", "#btn", function(){
var radios = $("input[type='radio']");
$.each(radios, function(index, element){
if ($(this).prop("checked") === true){
var radioID = element.id;
$("label").each(function(ind, elm){
if ($(elm).prop("for") == radioID){
console.log($(elm));
}
});
}
});
});
});
jsbin
For whatever reason that just prints out
-- [11:07:13.834] ({0:({}), context:({}), length:1}) @ http://jsbin.com/uniwum/2/edit:71
in the console. What have I done wrong?
$("input[type='radio']:checked").parent().text()
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