Before started jQuery, we need to download the jQuery library file. The jQuery is not a browser embedded like Javascript so to use jQuery on the webpage you need to download jQuery first. You can download the latest version of the jQuery file from the jquery.com website. You can also use the CDN link of jQuery. The CDN link can offer a performance benefit by hosting jQuery on servers spread across the globe.
The jQuery library is a JS file and you can add the jQuery using <script> tag which must be inside the <head> tag.
<head>
<script src="jquery-3.4.1.min.js"></script>
</head>
Download Jquery from CDN:
You can also download jQuery from external resources that host the jQuery like Google CDN, Microsoft CDN, CDNJS, etc.
jQuery CDN loads the jQuery from external sources so it improves the performance of the webpage.
After linking your webpage to a jquery library or CDN, you can use jQuery ob your webpage. jQuery syntax is started with $ function or jquery, both means to jQuery. jQuery can be attached to either <body> tag or <head> tag, for faster DOM loading prefer jQuery in the <body> tag after content means just before body closing.
The document.ready function using “$”:
<script>
$(document).ready(function(){
// your jquery code
})
</script>
The document.ready function using “jquery”:
<script>
jQuery(document).ready(function(){
// your jquery code
})
</script>
Jquery Document Ready Function:
It is recommended to start Jquery code in $(document).ready(function(){ }), or jQuery(document).ready(function(){ }). The document.ready function will execute jQuery functions after web page is fully ready.
<script>
$(document).ready(function(){
// your jquery code
})
</script>
Document Ready Function in short:
<script>
$(function(){
// your jquery code
})
</script>
Check Jquery:
If you want to check whether jQuery is working or not, open the console of your browser and write the following code.
If jQuery returns some functions it means jQuery is attached.
jQuery// (e,t){return new ct.fn.init(e,t,V)}
Also $==jQuery or $===jQuery should return true in console.
$==jQuery // true
$===jQuery // true
How to Check jQuery Version:
jQuery was started in 2006 with jQuery version 1.0 and the latest version of jQuery is 3.4.1. If you want to check which version of jQuery you are using, type jQuery.fn.jquery in the console, it will return the jQuery version.
jQuery.fn.jquery // return jquery version in string
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok