Reputation: 1339
i am beginner of jquery.How can i get the label value through jquery? Below is my coding
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.Label1.Text = "asdasd";
}
}
Html
<script src="../js/jquery-1.4.1.js" type="text/javascript"></script>
<script language ="javascript" type="text/javascript">
$(document).ready(function () {
var g = $('#<%=Label1.ClientID%>').text;
alert (g);
});
});
</script>
The alert function is not working :(
Upvotes: 0
Views: 9168
Reputation: 7218
Please correct your script as follows and try
<script language ="javascript" type="text/javascript">
$(document).ready(function () {
var g = $('#<%=Label1.ClientID%>').text();
alert (g);
});
//Comment out the last parenthesis
//});
</script>
Upvotes: 1
Reputation: 12652
You have one too many });
. Also you shouldn't have a space between alert
and the left parentheses. Also text
is a function so you should also add the ()
at the end of the statement.
Upvotes: 0
Reputation: 69362
You were close
var g = $('#<%=Label1.ClientID%>').text();
More information on text().
Upvotes: 0
Reputation: 80734
text
is a function, not a property. Put a pair of parentheses after it:
var g = $('#<%=Label1.ClientID%>').text();
Upvotes: 0