How to use jQuery in your .NET application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bharathreddy
    New Member
    • Aug 2006
    • 116

    #1

    How to use jQuery in your .NET application

    Here I am going to show you an example, how easy it is to use jQuery

    In this example i will display a hyperlink called "Click to show...". When the user clicks on this link some text will be displayed under this hyperlink which is in the div tag.

    Steps for example:
    1. First refer to the latest jquery javascript file. (You can download it from www.jquery.com)
    2. Then in the script area write the code:
      $(document).rea dy(function(){} )
      this statement says that when the html is ready, please execute the below statements in the function.
    3. By default i am hiding the div tag.
      $('div').hide() ;
      Note: If you have an id to the div tag in that case refer like $('div#idname')
    4. In the next step:
      $('a').click(fu nction(){}) when the anchor tag is clicked, please execute the following function.
    5. In the last step i am making the div tag visible.


    How it works:

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="jquery-1.4.2.js" type="text/javascript"></script>
        <script type="text/javascript">
           $(document).ready(function(){
           $('div').hide();
           $('a').click(function(){
           $('div').show();
           })
           })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <a id="sample" href="#">Click to show...</a>
        <div>
        
        This is simple example....
        </div>
        </form>
    </body>
    </html>

    jQuery is very easy to use and very powerful javascript querying tool to query html tags, css classes.

    Thanks
    Bharath Reddy VasiReddy
    Last edited by tlhintoq; Mar 26 '10, 06:58 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    Working...