The Wayback Machine - https://web.archive.org/web/20240920014719/https://www.geeksforgeeks.org/jquery-introduction/
Open In App

jQuery Introduction

Last Updated : 26 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM). jQuery simplifies HTML document traversing and manipulation, browser event handling, DOM animations, Ajax interactions, and cross-browser JavaScript development.

The jQuery is the only library available today that meets the needs of both designer types and programmer types. jQuery is widely famous for its philosophy of “Write less, do more.” This philosophy can be further elaborated as three concepts:

  • Finding some elements (via CSS selectors) and doing something with them (via jQuery methods) i.e. locate a set of elements in the DOM, and then do something with that set of elements.
  • Chaining multiple jQuery methods on a set of elements
  • Using the jQuery wrapper and implicit iteration

How to Add jQuery to HTML Page?

There are two methods to use jQuery in your HTML page.

The easiest method to include jQuery in your HTML page is by using a CDN link. CDN links hosted the jQuery files to the servers that can be easily used without downloading the files.

Include jQuery CDN link to the HTML page using <script> tag inside the head section of the page.

Syntax:

HTML
<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>jQuery Page</title>
  
    <!-- jQuery CDN Link -->
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js">
      </script>
</head>
  
<body>
    <!-- Page Content -->
</body>

</html>

2. Download the jQuery Files Locally and use Them

Visit the jQuery Official Website and download the latest version of jQuery. Then include the downloaded jQuery file into your project. Place the jquery.min.js file in a directory within your project, such as js/. Next, use <script> tag inside the <head> section to add jQuery file into your web page.

Syntax:

HTML
<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>jQuery Page</title>
  
    <!-- Local jQuery -->
    <script src="js/jquery.min.js"></script>
</head>
  
<body>
    <!-- Page Content -->
</body>

</html>

Basic Syntax for jQuery Function

In jQuery, the syntax for selecting and manipulating HTML elements is written as:

$(selector).action()

Where –

  • $ – This symbol is used to access jQuery. It’s a shorthand for the jQuery function.
  • (selector) – It specifies which HTML elements you want to target. The selector can be any valid CSS selector, such as a class, ID, or tag name.
  • .action() – It represents the action or method that you want to perform on the selected elements. Common actions include manipulating CSS properties, handling events, or performing animations.

For Example – Selects all <p> elements on the page and hides them.

$('p').hide();

Note: All jQuery methods are inside a document-ready event to prevent any jQuery code from running before the document is finished loading (is ready).

jQuery Basic Example

Create a basic HTML page with a <button> and a <p> element. When the user clicks the button, the content of the paragraph will be hidden.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <title>My First jQuery Example</title>

    <!-- Include jQuery from CDN Link -->
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js">
    </script>
</head>

<body>
    <p id="message">Hello, World!</p>
    
    <button id="hideButton">
        Hide Message
    </button>

    <!-- jQuery Script -->
    <script>
        $(document).ready(function() {
            $('#hideButton').click(function() {
                $('#message').hide();
            });
        });
    </script>
</body>

</html>

Output:

jQuery-Basic-Example


Why jQuery?

Some of the key points which support the answer for why to use jQuery:

  • It is incredibly popular, which is to say it has a large community of users and a healthy amount of contributors who participate as developers and evangelists.
  • It normalizes the differences between web browsers so that you don’t have to.
  • It is intentionally a lightweight footprint with a simple yet clever plugin architecture.
  • Its repository of plugins is vast and has seen steady growth since jQuery’s release.
  • Its API is fully documented, including inline code examples, which in the world of JavaScript libraries is a luxury. Heck, any documentation at all was a luxury for years.
  • It is friendly, which is to say it provides helpful ways to avoid conflicts with other JavaScript libraries.

Advantages of Using jQuery in a Project

  • Wide range of plug-ins. jQuery allows developers to create plug-ins on top of the JavaScript library.
  • Large development community
  • It has a good and comprehensive documentation
  • It is a lot more easy to use compared to standard javascript and other javascript libraries.
  • JQuery 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 jQuery more strong.

Disadvantages of Using jQuery in a Project

  • While JQuery has an impressive library in terms of quantity, depending on how much customization you require on your website, the functionality may be limited thus using raw javascript may be inevitable in some cases.
  • The JQuery javascript file is required to run JQuery commands, while the size of this file is relatively small (25-100KB depending on the server), it is still a strain on the client computer and maybe your web server as well if you intend to host the JQuery script on your own web server.

jQuery Introduction – FAQs

What is jQuery used for?

jQuery is a fast, lightweight, and feature-rich JavaScript library. It simplifies tasks such as HTML document traversal and manipulation, event handling, animation, and Ajax interactions. jQuery helps developers write less code to accomplish common tasks and ensures cross-browser compatibility.

What does jQuery stand for?

jQuery does not stand for anything specific. It is a name chosen for the library. The “j” in jQuery refers to “JavaScript,” indicating that it is a JavaScript library, while “Query” suggests its ability to query and manipulate HTML elements easily.

What is the difference between JavaScript and jQuery?

JavaScript is a programming language used to create interactive effects and dynamic content on websites. jQuery, on the other hand, is a JavaScript library that simplifies JavaScript programming by providing an easy-to-use API for tasks such as DOM manipulation, event handling, and animation. Essentially, jQuery is a tool built on top of JavaScript.

Is jQuery frontend or backend?

jQuery is a frontend library. It runs in the browser and is used for creating interactive and dynamic user interfaces. It does not handle backend tasks such as server-side logic or database management.

Is jQuery a tool or language?

jQuery is a tool, specifically a JavaScript library. It provides a set of pre-written functions and methods that simplify JavaScript programming. It is not a programming language itself but rather a library that enhances the capabilities of JavaScript.

Which is faster, JavaScript or jQuery?

JavaScript itself is generally faster because it operates directly in the browser’s JavaScript engine. jQuery adds an additional layer of abstraction and convenience, which can introduce slight overhead. However, the difference in performance is often negligible for most web applications.

Is jQuery a UI framework?

No, jQuery is not a UI framework. It is a JavaScript library used for manipulating the DOM, handling events, and performing animations.

Should I learn JavaScript or jQuery?

It is generally recommended to learn JavaScript first because it is the foundational language that jQuery is built upon. Understanding JavaScript will give you a deeper grasp of how jQuery works and enable you to use jQuery more effectively. Once you have a solid understanding of JavaScript, learning jQuery will be much easier and more beneficial.

What should I learn before jQuery?

Before learning jQuery, you should have a good understanding of the following:

  • HTML: Knowledge of HTML elements and structure.
  • CSS: Basic styling and layout concepts.
  • JavaScript: Fundamental concepts such as variables, functions, control structures, and DOM manipulation.

Is jQuery still relevant in 2024?

jQuery remains relevant, especially for maintaining legacy projects and for developers who prefer its simplicity. However, many modern web development projects favor newer libraries and frameworks like React, Vue.js, or Angular, which offer more advanced features and better performance for building complex applications.

What are jQuery plugins?

jQuery plugins are third-party extensions that provide additional functionality and features to jQuery. They are used to enhance or extend jQuery’s capabilities, such as adding new UI components, effects, or utilities. Plugins can be easily integrated into your project and typically come with documentation on how to use them.



Previous Article
Next Article

Similar Reads

jQuery Plugins Introduction
Plugins are the section of code and these codes are written in a JavaScript file. These JavaScript files are used to provide jQuery methods that work together with jQuery library methods. You can download jQuery plug-in from https://jquery.com/plugins How to create a jQuery plugin with methods: In Jquery Plug-in is a code that is needed in a standa
2 min read
jQuery Mobile Introduction
jQuery Mobile is an HTML5 based user interface system designed to make responsive websites and apps that are accessible on all smartphone, tablet, and desktop devices. jQuery Mobile framework takes the “write less, do more” mantra to the next level: Instead of writing unique applications for each mobile device or OS, the jQuery mobile framework all
2 min read
jQuery UI Introduction
jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. Whether you're building highly interactive web applications, or you just need to add a date picker to a form control, jQuery UI is the perfect choice. Features: jQueryUI is categorized into four groups, interactions
2 min read
Easy UI jQuery Introduction
Easy UI is an HTML5 framework for using user interface components based on jQuery, React, Angular, and Vue technologies. It helps in building features for interactive web and mobile applications saving a lot of time for developers. Features: We don't need to write much javascript code while using Easy UI; instead, you usually define the user interf
2 min read
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
Introduction to React Native
If you want to build mobile apps for both Android and iOS. What should you learn? The individual native languages for each app i.e, Java for Android and Swift/Objective-C for iOS?, Actually NO. Native Android and iOS development are quite different and can be expensive – first, the language itself is quite different, and second, all the underlying
3 min read
Introduction to Object Oriented Programming in JavaScript
As JavaScript is widely used in Web Development, in this article we will explore some of the Object Oriented mechanisms supported by JavaScript to get the most out of it. Some of the common interview questions in JavaScript on OOPS include: How is Object-Oriented Programming implemented in JavaScript? How does it differ from other languages? Can yo
7 min read
PHP | MySQL Database Introduction
What is MySQL? MySQL is an open-source relational database management system (RDBMS). It is the most popular database system used with PHP. MySQL is developed, distributed, and supported by Oracle Corporation. The data in a MySQL database are stored in tables which consists of columns and rows.MySQL is a database system that runs on a server.MySQL
4 min read
Django Introduction | Set 2 (Creating a Project)
Note- This article is in continuation of Django introduction. Popularity of Django Django is used in many popular sites like as: Disqus, Instagram, Knight Foundation, MacArthur Foundation, Mozilla, National Geographic etc. There are more than 5k online sites based on Django framework. ( Source ) Sites like Hot Frameworks assess the popularity of a
3 min read
Introduction to Xamarin | A Software for Mobile App Development and App Creation
The entire world is now surrounded by billions and trillions of mobile Tech which is inevitable. The major share of the development of mobile apps is taken by the Google's Android, Apple's iOS, and Microsoft's Windows. Every new learner or newbie in Mobile Development Domain finds himself in the dilemma of choosing the platform to start with. They
9 min read
WebGL Introduction
Creating interactive media content for the web traditionally required third-party apps or plug-ins installed in browsers. With the rise of open web standards and the need to support native graphics capabilities in the web browsers, WebGL was born to bring cross-browser compatibility and to be fully integrated with web standards. What is WebGL? WebG
4 min read
Introduction to Web Development and the Holy Trinity of it
Introduction and Holy Trinity of Web Development This article will give you an overview of the Front End Development, Back-End Development, and the Full Stack Development and will give you an idea about each of them in detail so that you can decide your field of interest for yourself. Starting from the basic book definition, ‘Web development refers
12 min read
Ajax Introduction
Introduction: The following tutorial will provide a short introduction to Ajax and its uses. Before understanding these terms see few practical examples to demonstrate the power of Ajax. Facebook, Instagram, Twitter etc are considered the situation when check news feed and if like someone post simply click the like button and the like count is adde
7 min read
Introduction to JavaScript Course - Learn how to build a task tracker using JavaScript
This is an introductory course about JavaScript that will help you learn about the basics of javascript, to begin with, the dynamic part of web development. You will learn the basics like understanding code structures, loops, objects, etc. What this course is about? In this course we will teach you about the basics of the scripting language i.e) Ja
4 min read
Introduction to Scripting Languages
All scripting languages are programming languages. The scripting language is basically a language where instructions are written for a run time environment. They do not require the compilation step and are rather interpreted. It brings new functions to applications and glue complex system together. A scripting language is a programming language des
3 min read
Introduction to React-Redux
The ones familiar with react will know that react is a component-based front end library tool that connects the various segments of the web page. In react, we use props (short for properties) in a component which allows the usage of non-static variables. With the help of props, we can pass these variables into various other components (child compon
5 min read
p5.js Introduction
p5.js is a JavaScript library used for creative coding. It is based on Processing which is a creative coding environment. The main focus of processing is to make it easy as possible for beginners to learn how to program interactive, graphical applications, to make a programming language more user-friendly by visualizing it. The advantage of using t
2 min read
PHP | Spreadsheet_Excel_Writer | Introduction
Introduction: Spreadsheet_Excel_Writer is a library written in PHP which helps to read from and write to different types of spreadsheet file formats with the help of given set of classes. Advantages: Easy and effective comparisons. Powerful analysis of large amounts of data. Splitting out large (or not so large) amounts of information in the form o
1 min read
Introduction to HTML CSS | Learn to Design your First Website in Just 1 Week
This is an introduction course to HTML and CSS which will help you learn all about the basics of HTML and CSS needed to begin with Web Development. Course Overview In this course we will teach you the basics of HTML and CSS along with building a project which will be a single page website. That is by following this course you will also get the chan
4 min read
Introduction to WebRTC
WebRTC stands for Web Real-Time Communication. It is an open source and free project that used to provide real-time communication to mobile applications and web browsers with the help of API's(Application Programming Interface). This project emerged as a new standard which extends the web-browsing model by enabling the browser in a peer-to-peer man
5 min read
Meteor Introduction and Environment Setup
Meteor is an open-source full-stack JavaScript platform that is useful for developing modern web and mobile applications. Meteor helps the developer to develop in one language. Meteor has several features that help for creating a responsive and reactive web or mobile application using JavaScript or different packages available in the framework. For
2 min read
HTML5 | Introduction
Introduction: HTML stands for Hyper Text Markup Language. It is used to design web pages using a markup language. HTML is an abbreviation of Hypertext and Markup language. Hypertext defines the link between the web pages. The markup language is used to define the text document within the tag which defines the structure of web pages. HTML 5 is the f
6 min read