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:

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

jQuery Example


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.

$("h3").css("color", "blue");  
You can also write the above code like this:
$(function() {  
$("h3").css("color", "blue");