Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get text of label that belongs to checked radio button

Tags:

jquery

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?

like image 677
1252748 Avatar asked Feb 28 '13 17:02

1252748


1 Answers

$("input[type='radio']:checked").parent().text()
like image 72
Melu Avatar answered Sep 30 '22 13:09

Melu