Home >>jQuery Tutorial >jQuery Example

jQuery Example

jQuery Example

Firstly, you need to use JavaScript file for jQuery to create the jQuery example. You have two options to link jQuery in you file. First you download the jQuery file from jQuery.com or use the CDN (Content Delivery Network) of jQuery file. jQuery is a framework developed by Google.

Note: you have to use script tag to write the code of jQuery.

Let’s see some examples of jQuery:

<html>  
<head>  
<title> jQuery Example</title>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>   
</head>  
<body>  
<h3>This is PHPTPOINT.</h3>  
<p>The second paragraph is selected.</p>  
<script>  
$(document).ready(function(){  
$("p").css("background-color", "orange");
$("h3").css("background-color", "yellow");  
});  
</script> 
</body>  
</html>

Output:
jQuery Example

This is PHPTPOINT.

The second paragraph is selected.

$(document).ready() and $()

You can write code inside the $(document).ready() is executed only once the page is ready to execute JavaScript code. You can also used shorthand notation $() only instead of using $(document).ready().Here $() is alias of jQuery.


//jQuery(document).ready(function()
//OR
$(document).ready(function() 
{  
$("h3").css("color", "blue");  
});  
You can also write the above code like this:
$(function() {  
$("h3").css("color", "blue");  
});  


No Sidebar ads