kids encyclopedia robot

jQuery facts for kids

Kids Encyclopedia Facts
jQuery
JQuery logo.svg
Original author(s) John Resig
Developer(s) The jQuery Team
Initial release August 26, 2006; 18 years ago (2006-08-26)
Stable release
3.7.1 / (August 28, 2023; 21 months ago (2023-08-28))
Preview release
4.0.0-beta / February 6, 2024; 16 months ago (2024-02-06)
Written in JavaScript
Platform See § Browser support
Size 27–274 KB
Type JavaScript library
License MIT

jQuery is a special JavaScript library. It helps make HTML web pages easier to build and change. It's great for things like handling events (like clicks), making cool CSS animations, and using Ajax to update parts of a page without reloading.

jQuery is free to use and change, thanks to its MIT License. As of August 2022, about 77% of the top 10 million websites use jQuery. This makes it the most popular JavaScript library by far!

Its design makes it simple to find parts of a web page, create animations, and react to user actions. Developers can also create special tools called plug-ins for jQuery. These plug-ins add even more cool features and effects to websites. This modular way of building helps create powerful and dynamic web pages.

jQuery's main features, like selecting and changing parts of a web page, created a new way of programming. This new style influenced other JavaScript tools and even helped create a standard way for browsers to select elements.

Big companies like Microsoft and Nokia have included jQuery in their own software. This shows how important and useful jQuery is in web development.

Contents

What is jQuery?

At its heart, jQuery helps you work with the Document Object Model (DOM). Think of the DOM as a map or a tree that shows all the parts of a web page. jQuery makes it much simpler to find, pick, and change these parts.

For example, you can use jQuery to find all the main titles (like `

` tags) on a page. Then, you can easily change their color or make them disappear when someone clicks on them. jQuery also makes it easy to handle events. An event is something that happens, like a mouse click or a key press. With jQuery, you can tell an element what to do when an event happens, all in one simple step. It also includes common web effects, like making things fade in or out. The main ideas behind using jQuery are:

  • Keeping code separate: jQuery helps keep your JavaScript code separate from your HTML code. This makes your code cleaner and easier to manage.
  • Short and clear code: jQuery uses short commands and lets you link many actions together. This makes your code shorter and easier to understand.
  • Works everywhere: Different web browsers sometimes handle JavaScript a bit differently. jQuery fixes these differences, so your code works the same way in most browsers.
  • Easy to expand: You can easily add new features and tools to jQuery by creating plug-ins.

History of jQuery

jQuery was first created in January 2006 by John Resig. He showed it at an event called BarCamp NYC. Today, a team of developers led by Timmy Willison keeps it updated.

At first, jQuery used a different license, but it soon switched to the MIT License in 2006. This license makes it very free and open for anyone to use.

How Popular is jQuery?

jQuery has become incredibly popular over the years:

  • In 2015, it was used on 62.7% of the top 1 million websites.
  • By 2019, this number grew to 80% of the top 1 million websites.
  • As of April 2021, jQuery was used by 77.8% of the top 10 million websites. This shows how widely it is used across the internet.

Key Features of jQuery

jQuery comes with many useful features that help web developers:

  • Selecting elements: It helps you pick out specific parts of a web page using a powerful tool called Sizzle.
  • Changing the page: You can easily change how elements look or what they do based on their names or classes.
  • Handling events: It makes it simple to react to things like clicks, mouse movements, or key presses.
  • Cool effects and animations: You can add smooth animations and visual effects to your web page elements.
  • Ajax: It helps you load and send data to a server without refreshing the whole page.
  • Managing tasks: It has special tools called Deferred and Promise objects to handle tasks that take time, like loading data.
  • Reading JSON: It can easily understand and use data formatted as JSON.
  • Adding new tools: You can extend jQuery's abilities with plug-ins.
  • Helpful tools: It includes many small tools, like checking if a browser supports a certain feature.
  • Works on many browsers: It makes sure your code works well across different web browsers.

Browser Support for jQuery

Newer versions of jQuery (like 3.0 and up) work with most modern web browsers. This includes recent versions of Firefox, Chrome, Safari, and Edge. It also supports Internet Explorer 9 and newer. For mobile devices, it works with iOS 7 and up, and Android 4.0 and up.

How to Use jQuery

The jQuery library is usually a single JavaScript file. This file contains all the tools you need for DOM, Events, and Ajax. You can add it to your web page by linking to a copy on your own server or from a public server. Google and Microsoft, for example, host copies of jQuery that you can use.

Here's an example of how you might link to a copy of jQuery on your own server:

<script src="jquery-3.5.1.min.js"></script>

And here's how you might link to it from a public server (like jQuery's own CDN):

<script
  src="https://code.jquery.com/jquery-3.5.1.min.js"
  integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
  crossorigin="anonymous"></script>

How jQuery Works

jQuery offers two main types of functions:

  • jQuery methods: These are used to work with specific parts of your web page.
  • Static utility functions: These are general tools that don't directly change parts of your page.

You can use `jQuery` or a shorter name, `$`, to access all these functions.

Working with Web Page Elements

To work with elements on your web page, you often start by using the `$` function with a CSS selector. A CSS selector is like an address that points to specific elements. For example, `$('div.test')` finds all `

` elements that have the class `test`. Once you have these elements, you can use jQuery methods to change them.

Chaining Actions Together

One cool thing about jQuery is "chaining." This means you can link many actions together in one line of code.

$('div.test')
  .on('click', handleTestClick)
  .addClass('foo');

This code finds all `div` elements with the class `test`. Then, it tells them to do something when clicked. Finally, it adds another class called `foo` to them.

Making New Web Page Elements

You can also use jQuery to create brand new elements on your web page. For example, you can create a new option for a drop-down list:

$('select#car-brands')
  .append($('<option>')
    .prop(value,"VAG")
    .text('Volkswagen')
  );

This code finds a drop-down list called `car-brands`. Then, it adds a new option for "Volkswagen" to it.

Using Ajax with jQuery

jQuery makes it easy to use Ajax. Ajax lets your web page send and receive data from a server without reloading the whole page. This makes web pages feel faster and smoother.

$.ajax({
  type: 'POST',
  url: '/process/submit.php',
  data: {
    name : 'John',
    location : 'Boston',
  },
}).then(function(msg) {
  alert('Data Saved: ' + msg);
}).catch(function(xmlHttpRequest, statusText, errorThrown) {
  alert(
    'Your form submission failed.\n\n'
      + 'XML Http Request: ' + JSON.stringify(xmlHttpRequest)
      + ',\nStatus Text: ' + statusText
      + ',\nError Thrown: ' + errorThrown);
});

This example sends some information (like a name and location) to a server. If it works, a message pops up saying "Data Saved." If there's a problem, it tells you what went wrong.

jQuery Plug-ins

jQuery is designed so that developers can easily create extra tools called plug-ins. These plug-ins add more features to jQuery. There are thousands of jQuery plug-ins available online. They can do all sorts of things, like helping with Ajax, creating cool data tables, or making things drag and drop.

You can find many plug-ins on the jQuery Project website. jQuery also has a "Learning Center" to help people learn JavaScript and how to make their own plug-ins.

jQuery Versions Over Time

Here's a look at some of the main versions of jQuery and what was new in them:

Version First Released Latest Update Size (KB) What's New or Important
1.0 August 26, 2006 (2006-08-26) The very first stable version.
1.3 January 14, 2009 (2009-01-14) 1.3.2 55.9 Introduced the Sizzle Selector Engine, which helps find elements faster.
1.5 January 31, 2011 (2011-01-31) 1.5.2 83.9 Improved how it handles tasks that run in the background (Ajax).
1.7 November 3, 2011 (2011-11-03) 1.7.2 (March 21, 2012 (2012-03-21)) 92.6 Added new ways to handle events like clicks (`.on()` and `.off()`).
1.9 January 15, 2013 (2013-01-15) 1.9.1 (February 4, 2013 (2013-02-04)) 90.5 Removed some older, less used features to make the code cleaner.
2.0 April 18, 2013 (2013-04-18) 2.0.3 (July 3, 2013 (2013-07-03)) 81.7 No longer supported older Internet Explorer browsers (IE 6-8) to make it faster and smaller.
3.0 June 9, 2016 (2016-06-09) 3.0.0 (June 9, 2016 (2016-06-09)) 84.3 Improved how it handles tasks that take time (Promises/A+).
3.4 April 10, 2019 (2019-04-10) 3.4.1 (May 1, 2019) 86.1 Made performance better and added some security fixes.
3.5 April 10, 2020 (2020-04-10) 3.5.1 (May 4, 2020) 87.4 Included more security fixes and new methods like `.even()` and `.odd()`.
3.7 May 11, 2023 (2023-05-11) 3.7.1 (August 28, 2023) 85.4 Added `.uniqueSort()` and made other improvements.
4.0 February 6, 2024 (2024-02-06) 4.0.0-beta 77.1 This is a beta version, meaning it's still being tested.

Testing jQuery Code

QUnit is a special tool used to test the jQuery project itself. The jQuery team created it to make sure their code works perfectly. It can also be used to test any other JavaScript code.

Other Ways to Build Websites

While jQuery has been a huge help in web development, some newer ways to build websites have appeared. Modern web browsers are now much better at handling JavaScript on their own. This means that sometimes, you don't need jQuery as much as you used to for basic tasks.

For example, GitHub stopped using jQuery on its pages in 2018. This shows that while jQuery is still very popular, there are now other good options for web developers.

See also

A robot, representing technology and programming.

  • Comparison of JavaScript-based web frameworks
  • jQuery Mobile
  • jQuery UI
  • Web framework
  • JavaScript library