Sunday, 7 February 2016

What is JQuery with a sample example ?



jQuery is a JavaScript library. It can:


  • Make your JavaScript code shorter, faster and cross browser.
  • Manipulate your HTML, like showing or hiding something from the page.
  • Handles events – it can do something when a user click a button or any other activity a user can do with a mouse.
  • Animation – for example make a part of your page fade in, fade out or just simply make something move.
  • AJAX – do a server request without refreshing your whole web page.

Code example:-


javaScript

   <script lang="javascript" type="text/javascript">
         $(document).ready(function () {
             $('#<%=Button1.ClientID%>').click(function () {

                 // this how to get text box value on button click
                 var txt = $('#<%=txt.ClientID%>').val();
                 // This how to set value to a label
                 $('#<%=lbl.ClientID%>').text(txt);
                 // This how make font bold os text
                 $('#<%=lbl.ClientID%>').css({'font-weight': 'bold', 'color':'red'});

                 $('#div1').css('background', 'yellow');
                 return false;
             });
           
         });

       </script>



HTML

     <div>   
        <Center>
        <table style="width: 60%">
            <tr>
            <td><asp:TextBox ID="txt" runat="server"></asp:TextBox></td>
            </tr>
             <tr>
             <td><asp:Label ID="lbl" runat="server" Text=""></asp:Label></td>
             </tr>
             <tr>
             <td> <asp:Button ID="Button1" runat="server" Text="Click me Now" /></td>
              </tr>
        </table>
            <div id="div1">
             <p> This is paragraph of  his might seem funny
                 because writing this jQuery tutorial
                 beginners in this blog is a little bit late.</p>

            </div>
        </Center>
    </div>



Before button click











After Entering some text and button click





















I hope its use for bignner to just undersatnd how its works.

No comments:

Post a Comment