Get label for input field

前端 未结 10 628
野趣味
野趣味 2021-01-11 09:53

I\'m doing a validation with Jquery and need to get the $label from each element with their own label. Now the alert() gives med [object object]. The best thing for me here

10条回答
  •  时光取名叫无心
    2021-01-11 10:15

    because you are sending an object to the alert function, if you want to get the content of the selected label you have to get it's html http://jsfiddle.net/s7pYX/2/

     $('input').each(function(){
     if ($(this).val() == '') {
    
     $element = $(this)
    
     var $label = $("label[for='"+$element.attr('id')+"']").html();
    
     alert($label)    
    
     }
    
     });  
    

提交回复
热议问题