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 many
articles relating to JQuery,
JavaScript, asp.net. 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</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>
|
Format text on label using Label control
ReplyDeleteplease contact me.
Deleterajni.luck@gmail.com