Use jQuery to find the label for a selected control or textbox
Use the attribute selector []
like [for='+ this.id +']
, where this.id
is the ID of the currently focus
ed label
$('input').on("focus", function() { var labelText = $('label[for='+ this.id +']').text(); console.log( labelText ); });
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><label for="inp">This Is My Label Value</label><input id="inp" type="text" >
In a HTML code like this one:
<label for="input-email">Email</label><input type="text" name="input-email" value="" />
You can find the label content like this:
$('label[for="input-email"]').html();
$("#ctl00_WebFormBody_txtPriceAdjustment").bind("click",function(){ alert($("label [for=" + this.id + "]").html());});
or possibly
alert($(this).closest("label").html());
depending on your markup you may just be able to select the next or previous siblings too.