Introduction:
Here I will explain how to get or set text to label in jQuery
or JavaScript or Get / set text to asp.net
label control in jQuery or JavaScript.
Description:
In previous articles I explained Get set asp.net control values in jQuery, jQuery Set Get textbox control value, jQuery highlight border & background of form controls when
validation fails, jQuery get dropdown selected value & text, JavaScript create watermark text for textbox and many
articles relating to JQuery,
JavaScript, asp.net,
code snippets. Now I will explain how to set text to label in jQuery
or JavaScript.
Get
Set html label Value in jQuery
To get html label value in jQuery we need to write the
code like as shown below
Get
html label value
var txt = $('#lbltxt').html();
Set html label value
$('#lbltxt').html("your
value");
|
To Get asp.net label Value
To get asp.net label value we
need to write the code like as shown below
var txt = $('#<%=lbltxt.ClientID%>').html();
or
var txt = $("[id$='lbltxt']").html()
|
Set
Asp.net label Value
$('#<%= lbltxt.ClientID%>').html('Your Value')
Or
$("[id$=' lbltxt']").html('Your Value')
|
For
Example check this post
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
</head>
<body>
<form id="form1"
runat="server">
<asp:Label ID="lbltxt"
runat="server"
>Welcome to aspdotnet-suresh.com</asp:Label>
<label ID="lblhtml"
runat="server"
>Welcome to html label</label>
<input type="button" id="btnclick" value="click" />
<script type="text/javascript">
$(function()
{
$("#btnclick").click(function() {
var txt = $('#<%=lbltxt.ClientID%>').html();
var txthtml = $('#lblhtml').html();
alert(txt);
alert(txthtml);
})
});
</script>
</form>
</body>
</html>
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
6 comments :
Hello Sir, This is abhinavsingh993, it is an Article that shows that you are a master of the asp.net
given the best solution in every time
thank you suresh
if want add value to label which is in gridview how it will..?
3
Thanks it worked for me! @anjankant
bhf
Note: Only a member of this blog may post a comment.