jQuery getting started

Last Updated: November 3, 2021

Getting started with jQuery is simple.

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Demo</title>
</head>
<body>
    <a href="http://jquery.com/">jQuery</a>
    <script src="jquery.js"></script>
    <script>
 
    // Your code goes here.
 
    </script>
</body>
</html>

You can download the latest version of the jQuery from https://jquery.com/download/

Launching Code on Document Ready

You can run the JS code inside onload() function or document.ready() function

window.onload = function() {
 
    alert( "welcome" );
 
};

Here is the document.ready()

$( document ).ready(function() {
 
    alert( "welcome" );
 
});

ready event will run your code fast.

Sample code for the click event

$( document ).ready(function() {
 
    $( "a" ).click(function( event ) {
 
        alert( "As you can see, the link no longer took you to jquery.com" );
 
        event.preventDefault();
 
    });
 
});