HTML 5 TutorialsLearning the basics of jQuery

Learning the basics of jQuery

In this session today we will study the implementation of jquery.

  • To implement jquery follow the steps and examples given below :

  1. First of all go to www.jquery.com and click on the download button as shown in the image :
  2. v1

  3. After you click on the download button, next window will appear.
  4. v2

  5. Now click on the Download the compressed production of jQuery and you will get the following window :
  6. v3

  7. Create a new folder then inside that folder right click choose the new text document give the name jquery.js and copy and paste the jquery code into it.
  8. 1

  9. Now name the file say jquery.js inside that paste your jquery code. Also right click on jquery.js file and open it in notepad++.and paste the downloaded code in the notepad++.
  10. 2

  11. After performing these steps your notepad++ window will look like as shown below:-
  12. v12

  13. Now create an index.html file. Open in an notepad++ and write the code given below.

               <html>
    </html>
    <title>Jquery
    </title>
    <head>
    <style>
        .red{ color:red;}
    </style>
    <script type="text/javascript" src="jquery.js"></script>
    </head>
    <body>
    <h1>This is an heading and this is first program in jquery</h1>
    <script>
    $('h1').addClass('red');
    </script>
    </body>
    </html>
    
  14. So after writing the code you will have the following look of your notepad++ window :
  15. v4

  16. Here in this example the jquery code is in tag inside the tag. If we put that code in head section this will change the output because we will be using that before “h1” section .(So in output it will not display the red color.)
  17. So write the following code :

    <html>
    </html>
    <title>Jquery
    </title>
    <head>
    <style>
        .red{ color:red;}
    </style>
    <script type="text/javascript" src="jquery.js"></script>
    <script>
    $('h1').addClass('red');
    </script>
    </head>
    <body>
    <h1>This is an heading and this is first program in jquery</h1>
    
    </body>
    </html>
    
  18. Thus you will have the following output :
  19. v6

  20. Here in this example the jquery is not called because it cannot find its class as we declared it in the head section .
  21. So to make the heading reflect in red color write the following code :

    <html>
    </html>
    <title>Jquery
    </title>
    <head>
    <style>
        .red{ color:red;}
    </style>
    <script type="text/javascript" src="jquery.js"></script>
    
    <script>
         $(document).ready( function(){
                 $('h1').addClass('red');
         });
    </script>
    
    </head>
    <body>
    <h1>This is an heading and this is first program in jquery</h1>
    
    </body>
    </html>
    
  22. So after writing the code you will have the follwoing look out of your window :
  23. v7

  24. So you will have the following output :
  25. v8

  26. You can visit the api.jquery.com which contain all these events and effect.
  27. To make some changes on button click implementing jquery write the following code in notepad++:

    <!Doctype html>
    <html>
    	<head>
    		<title>JQuery</title>
    		<style>
    			.red{color:red;}
    		</style>
    		<script type="text/javascript" src="jquery.js"></script>
    		<script>
    		$(document).ready(function(){
    			$('button').click(function(){
    				$('h1').html('Changed Text').slideToggle(200);
    			});
    		});
    		</script>
    		</head>
    	<body>
    	<button>Change Text</button>
    	
    	<h1>This is the text to change</h1>
    	
    	</body>
    </html>
    
  28. So after writing the code your notepad++ window will look like as shown below :
  29. v9

  30. So you will have the following output when you run your index.html file in browser :
  31. v11

  32. Thus we have learned basic implementations of jQuery.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exclusive content

- Advertisement -

Latest article

21,501FansLike
4,106FollowersFollow
106,000SubscribersSubscribe

More article

- Advertisement -