Get label for input field

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

    Instead of below line:

    var $label = $("label[for='"+$element.attr('id')+"']"
    

    Use the following code:

    var $label = $("label[for='"+$element.attr('id')+"']").text();
    

    You are getting only the object you need to use the .html() or .text() to get the text inside the label tag.

提交回复
热议问题