How to use jQuery with TypeScript ?
Last Updated :
28 Apr, 2025
In this article, we will learn how we can use jQuery with TypeScript and implement the features of both languages. The below approach can be used to implement jQuery in TypeScript.
By installing jQuery using the npm command
The jQuery can be installed in your current TypeScript project folder using the below commands and can be used to make changes in the application.
npm commands:
npm install jquery
npm install --save-dev @types/jquery
Once jQuery gets installed in your project use the below command to import and use it in your TypeScript file.
import variable_name_by_which_you_want_to_import_jQuery from 'jquery'
Example 1: The below code example shows how you can use jQuery in TypeScript by installing it in your project folder.
Please add the below HTML code to your index.html file.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Using jQuery in TypeScript</title>
</head>
<body>
<div style="text-align: center;">
<h1 style="color: green;">
GeeksforGeeks
</h1>
<button id="buttonId">
Click to show text using jQuery
</button>
<h3 id="dialog-container"></h3>
</div>
</body>
</html>
Now, add the below code to your index.ts file.
JavaScript
import $ from "jquery";
declare let global: any;
global.jQuery = $;
$("#buttonId").click(() => {
const myHTML: string = `
<b>
This text is shown using
the jQuery in TypeScript
by installing it using
npm package.
</b>`;
$('#dialog-container').html(myHTML);
});
Output:

Example 2: The below example will show the advance implementation of jQuery in TypeScript.
Add the below HTML code to your index.html file.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport"
content="width=device-width,
initial-scale=1.0" />
<title>
Using jQuery in TypeScript
</title>
</head>
<body>
<div style="text-align: center">
<h1 style="color: green">
GeeksforGeeks
</h1>
<button id="buttonId">
Show the below text
</button>
<h3 style="display: none;"
id="dialog-container">
This text is shown using
the jQuery in TypeScript
by installing it using
npm package.
</h3>
</div>
</body>
</html>
Add the below code in your index.ts file.
JavaScript
import $ from 'jquery';
$("#buttonId").click(() => {
$('#dialog-container').toggle();
if ($('#dialog-container').css('display') === 'none') {
$('#buttonId').html('Show the below text');
}
else {
$('#buttonId').html('Hide the below text');
}
});
Output:

Similar Reads
How to use TypeScript with React? TypeScript enhances JavaScript by adding strict type definitions, making your code more robust and maintainable. ReactJS, a popular library for building user interfaces, pairs excellently with TypeScript to create clean, efficient, and scalable codebases. Combining TypeScript with React offers a pow
3 min read
How to Use MathJS with TypeScript? Math.js library can be use with TypeScript to handle various mathematical tasks while getting the benefits of TypeScriptâs type safety and autocompletion. Integrating Math.js into your TypeScript project allows you to perform arithmetic, algebra, statistics, and more, with the added advantage of Typ
3 min read
How to Use TypeScript with Vite? Vite is a modern build tool known for its speed and efficiency. Using TypeScript with Vite combines Vite's fast development experience with TypeScript's strong static typing, enabling early error detection and more maintainable code. This integration enhances productivity and code quality in modern
3 min read
How to Test TypeScript with Jest? Jest, a powerful JavaScript testing framework, seamlessly integrates with TypeScript, providing all the tools needed to write and run tests for your TypeScript code, ensuring quality and reliability. It handles TypeScript compilation automatically, offers features like mocking and code coverage, and
3 min read
How to Use jQuery with Node.js ? jQuery is a popular JavaScript library primarily used for client-side scripting to simplify HTML document traversal, event handling, animation, and AJAX interactions. Although jQuery is designed for the browser, you might find scenarios where you want to use it on the server side with Node.js, such
3 min read