show-notice
hide-notice

Monday, 1 July 2013

jQuery Get Set Text to Label or How to Get / Set Label Text in jQuery


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>
Same way we can get any asp.net controls in JQuery

SHARE THIS POST   

2 comments :

Design by Gohilinfotech | www.gohilinfotech.blogspot.com