Search content within the blog

Monday, October 11, 2010

Retrieve DIV value in ASP.NET using jQuery

In this example, we will see how to retrieve and display the value of a div in an alert box, on the button click event.


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Retrieve Value of DIV in ASP.NET</title>
<script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script>

<script type="text/javascript">
$(function() {

$('input[id$=btnClick]').click(function () {
var divValue = $('#div1').html();
alert(divValue);
return false;

});

});

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="div1">Div Sample content</div><br />
<asp:Button ID="btnClick" runat="server" Text="Click" />
</div>
</form>
</body>
</html>

No comments:

Post a Comment