JQuery
JQuery is light weight javascript library and main role of jquery easily use javascript on your website.
Syntax of jquery:
$(Selector).action();
- $ Symbol to access jquery
- Selector is used to find HTML element
- Action is used for perform action on element
This Article, I want to explain Get and Set value of label using JQuery:
A. Get Value from Label
B. Set value to Label
- $('#lbl').val("Vishvajeet")
- $("#lbl").html("Vishvajeet")
- alert($('#lbl').val());
Example:
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head id="Head1" runat="server">
- <title></title>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function () {
- $('#btnGet').click(function () {
-
- alert($('#lbl').html());
- })
- $('#BtnSet').click(function () {
-
- $('#lbl').val("Set Value :- Vishvajeet")
- $("#lbl").html("Set Value :- Vishvajeet")
- alert($('#lbl').val());
- })
- });
- </script>
- </head>
- <body>
- <form id="form2" runat="server">
- <br />
- <div style="padding-left:100px">
- <asp:Label ID="lbl" runat="server" Text="Vishvajeet Pawar"></asp:Label>
- <br />
- <asp:Button ID="btnGet" runat="server" Text="Get Value" />
- <asp:Button ID="BtnSet" runat="server" Text="Set Value" />
- </div>
- </form>
- </body>
- </html>
A. Form Design:
B. Get Value from Label:
C. Set value to the Label: