Open In App

jQuery Tutorial

Last Updated : 18 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

jQuery is a lightweight open-source JavaScript library that simplifies manipulating the Document Object Model (DOM), handling events, and creating dynamic web experiences. The main purpose of jQuery is to simplify the usage of JavaScript on websites. jQuery simplifies complex JavaScript tasks with single-line methods, it makes your code more readable and maintainable. By learning jQuery, you can significantly improve the interactivity and responsiveness of your web pages.

In this jQuery tutorial, you’ll learn all the basic to advanced concepts of jQuery such as DOM manipulation and event handling, AJAX, animations, plugins, etc.

jQuery Tutorials

What is jQuery?

jQuery is a lightweight, “write less, do more” JavaScript library that simplifies web development. It provides an easy-to-use API for common tasks, making it much easier to work with JavaScript on your website. It streamlines web development by providing a concise syntax and powerful utilities for creating interactive and dynamic web pages.

Features of jQuery

Here are some key points about jQuery:

  1. DOM Manipulation: jQuery simplifies HTML DOM tree traversal and manipulation. You can easily select and modify elements on your web page.
  2. Event Handling: Handling user interactions (such as clicks or mouse events) becomes straightforward with jQuery.
  3. CSS Animations: You can create smooth animations and effects using jQuery.
  4. AJAX (Asynchronous JavaScript and XML): jQuery simplifies making asynchronous requests to the server and handling responses.
  5. Cross-Browser Compatibility: jQuery abstracts browser-specific inconsistencies, ensuring your code works consistently across different browsers.
  6. Community Support: A large community of developers actively contributes to jQuery, ensuring continuous updates and improvements.
  7. Plugins: jQuery has a wide range of plugins available for various tasks.

Getting Started with jQuery

1. Download the jQuery liberary:

You can download the jQuery library from the official website jquery.com and include it in your project by linking to it using a <script> tag, and host it on your server or local filesystem.

2. Include the jQuery Library:

1. Using jQuery Library Content Delivery Network (CDN) in your HTML project.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

2. Once the library is included, you can write jQuery code within <script> tags. jQuery code typically follows a specific syntax:

<script>  $(document).ready(function() {    // Your jQuery code here  });</script>

The $(document).ready(function() { ... }) function ensures your code executes only after the document is fully loaded, preventing errors.

Example:

In this example, we are using hover() and css() methods to change the style of heading content on mouse move over.

html
<!DOCTYPE html>
<html>
    <head>
        <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
        </script>

        <script>
            $(document).ready(function () {
                $("h1").hover(
                    function () {
                        $(this).css(
                            "color",
                            "green"
                        );
                    },
                    function () {
                        $(this).css(
                            "color",
                            "aliceblue"
                        );
                    }
                );
            });
        </script>
    </head>

    <body>
        <h1>GeeksforGeeks</h1>
    </body>
</html>

Output:

jQuery Basic Example

Learn More About jQuery Tutorial

jQuery Tutorial Complete References

jQuery Interview Questions and Answers (2024)

jQuery Selectors

jQuery offers a rich set of selectors to target specific elements on your webpage. Here are some commonly used ones:

  • ID Selector: Select an element with a specific ID using $("#element_id").
  • Class Selector: Target elements with a particular class using $(".class_name").
  • Tag Selector: Select all elements of a specific tag using the tag name (e.g., "h1").
  • Attribute Selector: Target elements based on their attributes (e.g., $("input[type='text']") selects all input elements with the type attribute set to “text”).

Essential jQuery Methods

  • html(): Set or get the HTML content of an element.
  • text(): Set or get the text content of an element.
  • attr(): Get or set the value of an element’s attribute.
  • addClass()/removeClass()/toggleClass(): Add, remove, or toggle a class for an element.

Advantages of jQuery

  • Wide range of plug-ins that allows developers to create plug-ins on top of the JavaScript library.
  • Large development community.
  • It is a lot easier to use compared to standard javascript and other javascript libraries.
  • It lets users develop Ajax templates with ease. Ajax enables a sleeker interface where actions can be performed on pages without requiring the entire page to be reloaded.
  • Being Light weight and a powerful chaining capabilities makes it more strong.

jQuery Cheat Sheet

The jQuery Cheat Sheet provides a quick reference guide for developers, summarizing common jQuery methods, selectors, events, and syntax, making it easier to write and understand jQuery code efficiently.

Recent Articles on jQuery



Similar Reads

jQuery Cheat Sheet – A Basic Guide to jQuery
What is jQuery?jQuery is an open-source, feature-rich JavaScript library, designed to simplify the HTML document traversal and manipulation, event handling, animation, and Ajax with an easy-to-use API that supports the multiple browsers. It makes the easy interaction between the HTML &amp; CSS document, Document Object Model (DOM), and JavaScript.
15+ min read
jQuery jQuery.fx.interval Property with example
The jQuery.fx.interval property in jQuery is used to modify the number of frames per second at which animations will run and to change the animation firing rate in milliseconds. Its default value is 13ms. Syntax: jQuery.fx.interval = milliseconds;Parameters: This method accepts single parameter milliseconds which is mandatory. It is used to specify
2 min read
jQuery jQuery.fx.off Property
The jQuery.fx.off property in jQuery is used to globally disable/enable all animations. Its default value is false which is used to allow animation to run normally. Syntax: jQuery.fx.off = true|false;Parameter: This event accepts two parameters as mentioned above and described below: true: It is used to specify that the animations should be disable
2 min read
jQuery jQuery.support Property
The jQuery.support property in jQuery contains a collection of properties that are used to represent the different browser features or bugs. Syntax: jQuery.support.propvalueParameters: This property contains a single parameter propvalue: which is required. It is used to specify the function to test for. The tests included are: ajaxboxModelchangeBub
1 min read
jQuery jquery Property
The jquery property is used to return the jQuery version number. Syntax $().jqueryExample: Return the version number. C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; h1 { color: green; } &lt;/style&gt; &lt;script src= &quot;https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt; &lt;/script&gt; &lt;script
1 min read
How to append a jQuery object to all paragraphs using jQuery ?
In this article, we will see how to append a jQuery object to all paragraphs using jQuery. Append means we add something to an existing element. The object is used to define a container for an external resource like a page, a picture, a media player, or a plug-in application. Used Methods: ready() Method: This method is used to specify a function t
2 min read
How to insert a jQuery object after all paragraphs using jQuery ?
The task is to insert a jQuery object after all the paragraphs using jQuery. Approach: Create DOM element or jQuery object using &lt;span&gt; tag.Create a paragraph using &lt;p&gt; tag.Create a button using button tag after clicking on which the object will be inserted after paragraph.Write a script that will call a function jQuery.after() which is
1 min read
Difference between jquery.size() and jquery.length
JQuery.size() method gives us the number of elements present. For Example, if we are calling the size() method for "p" tag, then it will return the number of "p" tags present on our page. Syntax: $(selector).size() Return value: It returns the number of “selector” present. Example: C/C++ Code &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt;
2 min read
How to remove close button from jQuery UI dialog using jQuery ?
In this article, we will learn how to remove the close button on the jQuery UI dialog using JavaScript, This can be achieved using the hide() method. jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. A dialog box is a temporary window. An application creates a dial
2 min read
How to make a JSON call using jQuery ?
Use the getJSON() function in jQuery to load JSON data. The getJSON() function uses a GET HTTP request to retrieve JSON-encoded data from the server. In this article, we will learn about the jQuery getJSON() function and its implementation through examples. Syntax: $(selector).getJSON(url, data, success(data, status, xhr)) Parameters: This method a
3 min read
Article Tags :
three90RightbarBannerImg