Get label for input field

前端 未结 10 656
野趣味
野趣味 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:13

    This isn't a great example but you could use the prev function from jQuery which will find the previous label before your selected component.

    $(document).ready( function() {
    
       $('input').each(function(){
           alert($(this).prev("label").html())
       });
    
    });
    

    JSFiddle: http://jsfiddle.net/gQnaM/

提交回复
热议问题