Get label for input field

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

    Check this DEMO

    $('input').each(function () {
        if ($(this).val() == '') {
    
            $element = $(this);
    
            var label = $element.closest("div").find("label").text();
    
            alert(label)
    
        }
    
    });
    

提交回复
热议问题