Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you update a label with javascript?

I have a javascript function that I am trying to get to update a label. If I replace the label with a textbox it works fine, but with the label nothing happens!

An example of a label:

<label id="163" name="163">Some text.</label>

javascript code:

$("#163").val("meep");
like image 953
Grayson Mitchell Avatar asked May 27 '24 11:05

Grayson Mitchell


4 Answers

The val method sets the value of an input element. It will have no effect on other elements, including <label>

You need to call the text method, which sets the text of any element.

For example:

$("#163").text("meep");
like image 130
SLaks Avatar answered Nov 18 '25 21:11

SLaks


The <label> element is not an input control, and it has no concept of a "value". It sounds like you are simply trying to change the text on the label. This can be achieved using the text(str) method:

$("#163").text("meep");
like image 30
Jørn Schou-Rode Avatar answered Nov 18 '25 20:11

Jørn Schou-Rode


Try text method :

$("#163").text("meep");
like image 20
Canavar Avatar answered Nov 18 '25 19:11

Canavar


Also, ID and NAME attributes should not start with a number, though most times this will not actually cause a problem.

like image 29
Ryan Joy Avatar answered Nov 18 '25 21:11

Ryan Joy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!