What’s New in jQuery 3.0 and How to Use It

Share this article

This article is part of a web development series from Microsoft. Thank you for supporting the partners who make SitePoint possible.
jQuery, the world’s most popular JavaScript library to date, has been a boon for a lot of us web developers out there. From the time of its initial release in 2006 till today, a lot of us web developers have included this wonderful library in our projects to make our life easier. Back in July 2015, jQuery announced the first alpha of jQuery 3.0 – a major release after a long time. Let’s take a look at what’s new in jQuery and how you can use it. Update: This article is now updated to include the jQuery 3.0 beta release on 14 Jan, 2016.

show() and hide()

Update: jQuery had tried a new implementation in alpha, but have reverted that change in the 3.0 beta. With the 3.0 beta, there’s now improved performance for hiding many elements. The jQuery team made the demo available here. One of the tests revealed this result: Chrome speed test The jQuery 2.0 version was up to 97% slower! In addition to this, another suggested way to go about showing and hiding elements is to use addClass() and removeClass() to control visibility. Or we can call hide() on the elements during the ready() call. Quick sample:
<!DOCTYPE HTML>
<html>
	<head>
	<style>
		.invisible{
			display: none;
		}
		.visible{
			background-color: deepskyblue;
			display:block;
		}
	</style>
	<script src="jquery-3.0.0-beta1.js"></script>
	<script>
		$(document).ready(function(){
			$("#div1").addClass("invisible");
			$("#toggle").click(function(){
				$("#div1").removeClass("visible");
				$("#div1").addClass("invisible");
			});
		});
	</script>
	<title>Control Visibility</title>
	</head>
	<body>
		<p>Hello!</p>
		<div id="div1">Can you see this?</div>
		<button id="toggle">Click me</button>
	</body>	
</html>
Control visibility Control visibility

Nomenclature for .data() Key Names

The jQuery team changed the .data() implementation to closely match the HTML5 dataset specification. If the key in the data-* attribute contains a digit, the digits will no longer participate in the conversion. Consider this example: With jQuery 2.1.4: data attribute in jQuery 2.1.4 The console window does not display the object. With jQuery 3.0.0: data attribute in jQuery 3.0.0 The key is converted to foo-42Name as digits do not participate in the conversion to camel case now. Hence, we get the output in console. The fiddle is available at https://jsfiddle.net/nWCKt/25/. You can change the jQuery versions to see the changes. Similarly, if we want to display all the data using data() with no arguments, the number of arguments will change in the two versions of jQuery if any of the key names of data-* attributes had a digit immediately after the hyphen (-), like in the above case. HTML:
<div data-foo-42-name="namebar" data-foo-42-yes="yesbar"></div>
JavaScript:
var div = $('div');
console.log(div.data());
In jQuery 3.0, this would show the object {foo-42Name: “namebar”, foo-42Yes: “yesbar”}. But in an earlier version, it would show an empty object {}.

width() and height() return decimal values

Some browsers return subpixel values for width and height. jQuery now returns decimal values for .width()
, .height(), .css(“width”), and .css(“height”) whenever the browser supports it. For users looking for subpixel precision for designing webpages, this may serve as good news.

.load(), .unload(), and .error() methods are removed

These methods which were deprecated earlier, have now been removed from in jQuery 3.0.0 beta. The recommended way is to use .on() to handle these events. Short example: HTML:
<img src="space-needle.png" alt="Space Needle" id="spacen">
JavaScript: Earlier implementation (now defunct)
$( "#spacen" ).load(function() {
  // Handler implementation
});
Recommended implementation:
$( "#spacen" ).on( "load", function() {
  // Handler implementation
});

jQuery Objects are Iterable Now

Iterating over jQuery objects is possible now, using ES2015 for-of. So, you can use things like:
for ( node of $( "<div id=spacen>" ) ) {
  console.log( node.id ); // Returns ‘spacen’
}
(Source here)

jQuery Animations Now Use requestAnimationFrame API at the Backend

All modern browsers now support requestAnimationFrame (status here: http://caniuse.com/#search=requestAnimationFrame). With its popular support, jQuery will use this API when performing animations. Advantages include smoother animations and less CPU-intensive animations (hence, saving battery on mobiles).

Enhancement of .unwrap() Method

.unwrap() method, which lets you remove the parents of the matched elements from the DOM, did not use to accept parameters earlier. This could be an issue if someone wants to unwrap basis a condition set on the parent. With jQuery 3.0.0 beta, .unwrap() accepts the jQuery selector parameter to handle this.

jQuery.Deferred Updated to be Promises/A+ Compatible

A promise is an eventual result of an asynchronous operation – it is an object that promises to deliver a result in future. The primary way of interacting with promise is through the then method, which registers callbacks. Using Promise for asynchronous work in JavaScript is becoming increasingly popular these days. Promises/A+ is an open standard for interoperable JavaScript promises. (For more info, check out this link: https://promisesaplus.com/) From jQuery documentation, the Deferred object is a chainable utility object created by calling the jQuery.Deferred() method. It can register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function. In jquery 3.0.0 beta, the jQuery.Deferred objects are updated to be compatible with Promises/A+ and ES2015 Promises. Hence, there were major changes madeto .then() method.

Better Handling of Error Cases

This version of jQuery has better handling of error cases – incorrect requests which have been ignored till now, throw up errors. For example: Consider offset, which gets the current coordinates of the first element, in the set of matched elements, relative to the document. If you were trying to find out the offset for a window with earlier versions of jQuery, you’d get the result as {top: 0, left: 0} instead of an error being thrown, since the offset for a window does not make sense. With the 3.0 beta version, it will now throw up an error. Another example: $("#") now throws an error rather than returning 0-length collection.

Massive Speedups for Custom Selectors Like :visible

There have been massive performance improvements made when selectors like :visible are used in a document multiple times. Internally, this is done by caching – so the first time the selector is used, the result is the same. But, each call after that gives results way faster, since caching comes into play. Timmy Willison from jQuery reported that it leads to about 17x improvement for the :visible selector! These were among some of the major updates made. Entire list is available on their official blog: http://blog.jquery.com/2016/01/14/jquery-3-0-beta-released/.

Where to Download the Latest Version

There are two releases:
  1. You can get the latest version directly from: https://code.jquery.com/jquery-3.0.0-beta1.js
  2. The minified version is available from: https://code.jquery.com/jquery-3.0.0-beta1.min.js
It’s also available on npm:
npm install jquery@3.0.0-beta1
With Microsoft dropping support for IE8, IE9 and IE10, jQuery has dropped support for IE8 in jQuery 3.0. If you need IE6-8 support, you should use the latest 1.12 release. Feel free to try out this beta version and give feedback on https://github.com/jquery/jquery. It’s worth a shot!

More Hands-on with Web Development

This article is part of the web development series from Microsoft evangelists and engineers on practical JavaScript learning, open source projects, and interoperability best practices including Microsoft Edge browser and the new EdgeHTML rendering engine. We encourage you to test across browsers and devices including Microsoft Edge – the default browser for Windows 10 – with free tools on dev.microsoftedge.com: More in-depth learning from our engineers and evangelists: Our community open source projects: More free tools and back-end web dev stuff:

Frequently Asked Questions about jQuery Use

What are the new features in jQuery 3?

jQuery 3 comes with a host of new features and improvements. One of the most significant changes is the introduction of the ‘requestAnimationFrame’ for animations. This feature makes animations smoother and less resource-intensive. jQuery 3 also includes a new method for handling errors, called ‘catch’. This method makes it easier to manage and debug asynchronous code. Other notable features include improved performance, better handling of asynchronous operations, and more robust event handling.

How does jQuery 3 differ from its previous versions?

jQuery 3 is a major update from its previous versions. It includes several new features, improvements, and bug fixes that make it more powerful and easier to use. Some of the key differences include the use of ‘requestAnimationFrame’ for animations, a new ‘catch’ method for error handling, and improved performance. Additionally, jQuery 3 has dropped support for older browsers, making it more streamlined and efficient.

What is the ‘requestAnimationFrame’ in jQuery 3?

The ‘requestAnimationFrame’ is a new feature in jQuery 3 that is used for animations. It allows the browser to optimize the animation, making it smoother and less resource-intensive. This feature is particularly useful for animations that involve complex calculations or multiple elements.

How does the ‘catch’ method work in jQuery 3?

The ‘catch’ method in jQuery 3 is used for error handling. It is a part of Promises/A+ specification and is used to catch any errors that occur during the execution of a promise. This method makes it easier to manage and debug asynchronous code.

How has the performance improved in jQuery 3?

jQuery 3 includes several performance improvements. These include faster event handling, improved performance of common tasks, and better handling of asynchronous operations. These improvements make jQuery 3 faster and more efficient than its previous versions.

What is the support for older browsers in jQuery 3?

jQuery 3 has dropped support for older browsers. This means that it no longer supports Internet Explorer 6, 7, or 8. This decision was made to make jQuery more streamlined and efficient. However, for those who still need to support these older browsers, jQuery offers a version called jQuery Compat.

What is jQuery Compat?

jQuery Compat is a version of jQuery that includes support for older browsers, including Internet Explorer 6, 7, and 8. It includes all the features and improvements of jQuery 3, but with added compatibility for these older browsers.

How can I migrate from an older version of jQuery to jQuery 3?

Migrating from an older version of jQuery to jQuery 3 can be done using the jQuery Migrate plugin. This plugin helps to identify and fix any issues that may arise during the migration process.

What is the jQuery Migrate plugin?

The jQuery Migrate plugin is a tool that helps to simplify the process of migrating from an older version of jQuery to a newer one. It identifies deprecated features, warns about potential issues, and can even restore deprecated features if necessary.

Where can I find more information about jQuery 3?

More information about jQuery 3 can be found on the official jQuery website. The website includes a detailed guide on the new features and improvements in jQuery 3, as well as a comprehensive API documentation.

Saurabh KirtaniSaurabh Kirtani
View Author

As a Technology Evangelist at Microsoft, Saurabh Kirtani enjoys getting developers get on-board with various technologies. He has worked majorly on web development (JavaScript, HTML/CSS3, RWD, MVC), IoT-based solutions, Azure and also on game development by Unity. He has been an active speaker at various developer camps and conferences. Other than technology, he likes to travel, follow cricket, watch comedy/suspense TV shows, and spend his time on Quora!

JavaScriptjQuerymdnweb development
Share this article
Read Next
7 Easy Ways to Make a Magento 2 Website Faster
7 Easy Ways to Make a Magento 2 Website Faster
Konstantin Gerasimov
Powerful React Form Builders to Consider in 2024
Powerful React Form Builders to Consider in 2024
Femi Akinyemi
Quick Tip: How to Animate Text Gradients and Patterns in CSS
Quick Tip: How to Animate Text Gradients and Patterns in CSS
Ralph Mason
Sending Email Using Node.js
Sending Email Using Node.js
Craig Buckler
Creating a Navbar in React
Creating a Navbar in React
Vidura Senevirathne
A Complete Guide to CSS Logical Properties, with Cheat Sheet
A Complete Guide to CSS Logical Properties, with Cheat Sheet
Ralph Mason
Using JSON Web Tokens with Node.js
Using JSON Web Tokens with Node.js
Lakindu Hewawasam
How to Build a Simple Web Server with Node.js
How to Build a Simple Web Server with Node.js
Chameera Dulanga
Building a Digital Fortress: How to Strengthen DNS Against DDoS Attacks?
Building a Digital Fortress: How to Strengthen DNS Against DDoS Attacks?
Beloslava Petrova
Crafting Interactive Scatter Plots with Plotly
Crafting Interactive Scatter Plots with Plotly
Binara Prabhanga
GenAI: How to Reduce Cost with Prompt Compression Techniques
GenAI: How to Reduce Cost with Prompt Compression Techniques
Suvoraj Biswas
How to Use jQuery’s ajax() Function for Asynchronous HTTP Requests
How to Use jQuery’s ajax() Function for Asynchronous HTTP Requests
Aurelio De RosaMaria Antonietta Perna
Quick Tip: How to Align Column Rows with CSS Subgrid
Quick Tip: How to Align Column Rows with CSS Subgrid
Ralph Mason
15 Top Web Design Tools & Resources To Try in 2024
15 Top Web Design Tools & Resources To Try in 2024
SitePoint Sponsors
7 Simple Rules for Better Data Visualization
7 Simple Rules for Better Data Visualization
Mariia Merkulova
Cloudways Autonomous: Fully-Managed Scalable WordPress Hosting
Cloudways Autonomous: Fully-Managed Scalable WordPress Hosting
SitePoint Team
Best Programming Language for AI
Best Programming Language for AI
Lucero del Alba
Quick Tip: How to Add Gradient Effects and Patterns to Text
Quick Tip: How to Add Gradient Effects and Patterns to Text
Ralph Mason
Logging Made Easy: A Beginner’s Guide to Winston in Node.js
Logging Made Easy: A Beginner’s Guide to Winston in Node.js
Vultr
How to Optimize Website Content for Featured Snippets
How to Optimize Website Content for Featured Snippets
Dipen Visavadiya
Psychology and UX: Decoding the Science Behind User Clicks
Psychology and UX: Decoding the Science Behind User Clicks
Tanya Kumari
Build a Full-stack App with Node.js and htmx
Build a Full-stack App with Node.js and htmx
James Hibbard
Digital Transformation with AI: The Benefits and Challenges
Digital Transformation with AI: The Benefits and Challenges
Priyanka Prajapat
Quick Tip: Creating a Date Picker in React
Quick Tip: Creating a Date Picker in React
Dianne Pena
How to Create Interactive Animations Using React Spring
How to Create Interactive Animations Using React Spring
Yemi Ojedapo
10 Reasons to Love Google Docs
10 Reasons to Love Google Docs
Joshua KrausZain Zaidi
How to Use Magento 2 for International Ecommerce Success
How to Use Magento 2 for International Ecommerce Success
Mitul Patel
5 Exciting New JavaScript Features in 2024
5 Exciting New JavaScript Features in 2024
Olivia GibsonDarren Jones
Tools and Strategies for Efficient Web Project Management
Tools and Strategies for Efficient Web Project Management
Juliet Ofoegbu
Choosing the Best WordPress CRM Plugin for Your Business
Choosing the Best WordPress CRM Plugin for Your Business
Neve Wilkinson
ChatGPT Plugins for Marketing Success
ChatGPT Plugins for Marketing Success
Neil Jordan
Managing Static Files in Django: A Comprehensive Guide
Managing Static Files in Django: A Comprehensive Guide
Kabaki Antony
The Ultimate Guide to Choosing the Best React Website Builder
The Ultimate Guide to Choosing the Best React Website Builder
Dianne Pena
Exploring the Creative Power of CSS Filters and Blending
Exploring the Creative Power of CSS Filters and Blending
Joan Ayebola
How to Use WebSockets in Node.js to Create Real-time Apps
How to Use WebSockets in Node.js to Create Real-time Apps
Craig Buckler
Best Node.js Framework Choices for Modern App Development
Best Node.js Framework Choices for Modern App Development
Dianne Pena
SaaS Boilerplates: What They Are, And 10 of the Best
SaaS Boilerplates: What They Are, And 10 of the Best
Zain Zaidi
Understanding Cookies and Sessions in React
Understanding Cookies and Sessions in React
Blessing Ene Anyebe
Enhanced Internationalization (i18n) in Next.js 14
Enhanced Internationalization (i18n) in Next.js 14
Emmanuel Onyeyaforo
Essential React Native Performance Tips and Tricks
Essential React Native Performance Tips and Tricks
Shaik Mukthahar
How to Use Server-sent Events in Node.js
How to Use Server-sent Events in Node.js
Craig Buckler
Five Simple Ways to Boost a WooCommerce Site’s Performance
Five Simple Ways to Boost a WooCommerce Site’s Performance
Palash Ghosh
Elevate Your Online Store with Top WooCommerce Plugins
Elevate Your Online Store with Top WooCommerce Plugins
Dianne Pena
Unleash Your Website’s Potential: Top 5 SEO Tools of 2024
Unleash Your Website’s Potential: Top 5 SEO Tools of 2024
Dianne Pena
How to Build a Chat Interface using Gradio & Vultr Cloud GPU
How to Build a Chat Interface using Gradio & Vultr Cloud GPU
Vultr
Enhance Your React Apps with ShadCn Utilities and Components
Enhance Your React Apps with ShadCn Utilities and Components
David Jaja
10 Best Create React App Alternatives for Different Use Cases
10 Best Create React App Alternatives for Different Use Cases
Zain Zaidi
Control Lazy Load, Infinite Scroll and Animations in React
Control Lazy Load, Infinite Scroll and Animations in React
Blessing Ene Anyebe
Building a Research Assistant Tool with AI and JavaScript
Building a Research Assistant Tool with AI and JavaScript
Mahmud Adeleye
Understanding React useEffect
Understanding React useEffect
Dianne Pena
Web Design Trends to Watch in 2024
Web Design Trends to Watch in 2024
Juliet Ofoegbu
Building a 3D Card Flip Animation with CSS Houdini
Building a 3D Card Flip Animation with CSS Houdini
Fred Zugs
How to Use ChatGPT in an Unavailable Country
How to Use ChatGPT in an Unavailable Country
Dianne Pena
An Introduction to Node.js Multithreading
An Introduction to Node.js Multithreading
Craig Buckler
How to Boost WordPress Security and Protect Your SEO Ranking
How to Boost WordPress Security and Protect Your SEO Ranking
Jaya Iyer
Understanding How ChatGPT Maintains Context
Understanding How ChatGPT Maintains Context
Dianne Pena
Building Interactive Data Visualizations with D3.js and React
Building Interactive Data Visualizations with D3.js and React
Oluwabusayo Jacobs
JavaScript vs Python: Which One Should You Learn First?
JavaScript vs Python: Which One Should You Learn First?
Olivia GibsonDarren Jones
13 Best Books, Courses and Communities for Learning React
13 Best Books, Courses and Communities for Learning React
Zain Zaidi
5 jQuery.each() Function Examples
5 jQuery.each() Function Examples
Florian RapplJames Hibbard
Implementing User Authentication in React Apps with Appwrite
Implementing User Authentication in React Apps with Appwrite
Yemi Ojedapo
AI-Powered Search Engine With Milvus Vector Database on Vultr
AI-Powered Search Engine With Milvus Vector Database on Vultr
Vultr
Understanding Signals in Django
Understanding Signals in Django
Kabaki Antony
Why React Icons May Be the Only Icon Library You Need
Why React Icons May Be the Only Icon Library You Need
Zain Zaidi
View Transitions in Astro
View Transitions in Astro
Tamas Piros
Getting Started with Content Collections in Astro
Getting Started with Content Collections in Astro
Tamas Piros
What Does the Java Virtual Machine Do All Day?
What Does the Java Virtual Machine Do All Day?
Peter Kessler
Become a Freelance Web Developer on Fiverr: Ultimate Guide
Become a Freelance Web Developer on Fiverr: Ultimate Guide
Mayank Singh
Layouts in Astro
Layouts in Astro
Tamas Piros
.NET 8: Blazor Render Modes Explained
.NET 8: Blazor Render Modes Explained
Peter De Tender
Mastering Node CSV
Mastering Node CSV
Dianne Pena
A Beginner’s Guide to SvelteKit
A Beginner’s Guide to SvelteKit
Erik KückelheimSimon Holthausen
Brighten Up Your Astro Site with KwesForms and Rive
Brighten Up Your Astro Site with KwesForms and Rive
Paul Scanlon
Which Programming Language Should I Learn First in 2024?
Which Programming Language Should I Learn First in 2024?
Joel Falconer
Managing PHP Versions with Laravel Herd
Managing PHP Versions with Laravel Herd
Dianne Pena
Accelerating the Cloud: The Final Steps
Accelerating the Cloud: The Final Steps
Dave Neary
An Alphebetized List of MIME Types
An Alphebetized List of MIME Types
Dianne Pena
The Best PHP Frameworks for 2024
The Best PHP Frameworks for 2024
Claudio Ribeiro
11 Best WordPress Themes for Developers & Designers in 2024
11 Best WordPress Themes for Developers & Designers in 2024
SitePoint Sponsors
Top 10 Best WordPress AI Plugins of 2024
Top 10 Best WordPress AI Plugins of 2024
Dianne Pena
20+ Tools for Node.js Development in 2024
20+ Tools for Node.js Development in 2024
Dianne Pena
The Best Figma Plugins to Enhance Your Design Workflow in 2024
The Best Figma Plugins to Enhance Your Design Workflow in 2024
Dianne Pena
Harnessing the Power of Zenserp for Advanced Search Engine Parsing
Harnessing the Power of Zenserp for Advanced Search Engine Parsing
Christopher Collins
Build Your Own AI Tools in Python Using the OpenAI API
Build Your Own AI Tools in Python Using the OpenAI API
Zain Zaidi
The Best React Chart Libraries for Data Visualization in 2024
The Best React Chart Libraries for Data Visualization in 2024
Dianne Pena
7 Free AI Logo Generators to Get Started
7 Free AI Logo Generators to Get Started
Zain Zaidi
Turn Your Vue App into an Offline-ready Progressive Web App
Turn Your Vue App into an Offline-ready Progressive Web App
Imran Alam
Clean Architecture: Theming with Tailwind and CSS Variables
Clean Architecture: Theming with Tailwind and CSS Variables
Emmanuel Onyeyaforo
How to Analyze Large Text Datasets with LangChain and Python
How to Analyze Large Text Datasets with LangChain and Python
Matt Nikonorov
6 Techniques for Conditional Rendering in React, with Examples
6 Techniques for Conditional Rendering in React, with Examples
Yemi Ojedapo
Introducing STRICH: Barcode Scanning for Web Apps
Introducing STRICH: Barcode Scanning for Web Apps
Alex Suzuki
Using Nodemon and Watch in Node.js for Live Restarts
Using Nodemon and Watch in Node.js for Live Restarts
Craig Buckler
Task Automation and Debugging with AI-Powered Tools
Task Automation and Debugging with AI-Powered Tools
Timi Omoyeni
Quick Tip: Understanding React Tooltip
Quick Tip: Understanding React Tooltip
Dianne Pena
12 Outstanding AI Tools that Enhance Efficiency & Productivity
12 Outstanding AI Tools that Enhance Efficiency & Productivity
Ilija Sekulov
React Performance Optimization
React Performance Optimization
Blessing Ene Anyebe
Introducing Chatbots and Large Language Models (LLMs)
Introducing Chatbots and Large Language Models (LLMs)
Timi Omoyeni
Migrate to Ampere on OCI with Heterogeneous Kubernetes Clusters
Migrate to Ampere on OCI with Heterogeneous Kubernetes Clusters
Ampere Computing
Scale Your React App with Storybook and Chromatic
Scale Your React App with Storybook and Chromatic
Daine Mawer
10 Tips for Implementing Webflow On-page SEO
10 Tips for Implementing Webflow On-page SEO
Milan Vracar
Get the freshest news and resources for developers, designers and digital creators in your inbox each week