views:

108

answers:

4

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");
+4  A: 

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");
Jørn Schou-Rode
+5  A: 

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");
SLaks
awesome! thanks
Grayson Mitchell
+2  A: 

Try text method :

$("#163").text("meep");
Canavar
+2  A: 

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

atxryan