I'm trying to select the text of the "label" element amongst a large document of similar elements differentiated by the value of the "for" attribute.
If trying to select it like so $("label[for=cu1]").text()
This is not working, nor is selecting the root element.
Here is the example node that contains the label w/ text I'm trying to select. Please keep in mind that there are many other similar nodes, with only the "for" attribute differing (and the id of the input element, if that helps) ...
<div class="verticalfield">
<label class="verticalfield" for="cu1">Custom 1</label>
<input id="cu1" class="inputtext long" type="text" value="" maxlength="255" name="cu1">
</div>
I'm going to venture a guess and say that you are trying to use $("label[for=cu1]").text()
before that label has been loaded in the DOM. Try something like this:
$(function () {
//other important stuff
var text = $("label[for=cu1]").text();
//etc.
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With