brgdotnet
asked on
How to set text of a label control using JQuery
I am trying to set the text of a lable control using JQuery. The Label control is an Asp.net label control.
Can someone look at my two lines of JQuery below, that are not working. I am not sure if the JQuery syntact is correct.
$('#fooLabel').val('Hello World'); // first try Not working
$('fooLabel').val(''Hello World'); // Second tryn Not working
<asp:Label ID="fooLabel" visible="true" runat="server"></asp:Label >
Can someone look at my two lines of JQuery below, that are not working. I am not sure if the JQuery syntact is correct.
$('#fooLabel').val('Hello World'); // first try Not working
$('fooLabel').val(''Hello World'); // Second tryn Not working
<asp:Label ID="fooLabel" visible="true" runat="server"></asp:Label
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Edited above to set the text not val
ASKER
Hi Gary,
Are you saying that if I remove the runat=server that it will fix the problem? Also, the JQuery is in the same page of the Aspx file. Not in an external file.
Are you saying that if I remove the runat=server that it will fix the problem? Also, the JQuery is in the same page of the Aspx file. Not in an external file.
If it's in the same page then you can just use the first example
If you remove the runat="server" then this will work
$('#fooLabel').text('Hello World');
This is also assuming the jquery code is in a document ready function or at the end of the page.
If you remove the runat="server" then this will work
$('#fooLabel').text('Hello
This is also assuming the jquery code is in a document ready function or at the end of the page.