Reputation: 6912
I have a text input with a label:
<li data-role="fieldcontain">
<label for="number">Amount:</label>
<input type="number" name="number" id="vitalamount" value="" />
</li>
I'm now trying to change the label of the input, but the following code didn't work.
$("#vitalamount").attr("label","something else");
Upvotes: 1
Views: 127
Reputation: 29025
If you don't include the form field inside the label tag, then you should use the for attribute to associate it with the id of the form element you want to label.
So, put id
in for
attribute not name
.
Amount:
Now, if you the id
of input as vitalamount
$('label[for="vitalamount"]').html('New value of label');
Upvotes: 0
Reputation: 144739
attr
modifies the attributes of an element not it's sibling elements, you can use prev()
or siblings
for selecting the label
and changing it's texts:
$("#vitalamount").siblings("label").text('something else');
Upvotes: 3