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 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
How to use jQuery Each Function in TypeScript ? jQuery is a JavaScript library that can be integrated with TypeScript and the features of both can be used together to enhance the interactivity of the application. In this post, we will learn, how we can use each() method of jQuery in TypeScript with its practical implementation. Before going to th
2 min read
How to Use Fetch in TypeScript ? In TypeScript, fetching the data from any server or API using fetch() API is not the same as we used to do it in Plain or Vanilla JavaScript. Let us see how we can use the fetch API to fetch data from any server or API in TypeScript.NOTE: Before using this code, please make sure that you have jQuery
4 min read
How to Pass Over an Element Using TypeScript and jQuery ? This article will show how we can pass an HTML element to a function using jQuery and TypeScript together. There are different ways available in which we can pass an element to a function using TypeScript and jQuery as listed below. Before moving on to the implementation, make sure that you have jQu
4 min read
How to use jQuery getScript ? The jQuery .getScript() method loads a JavaScript file from a server using the GET HTTP method and then executes it. Syntax: $.getScript(url,[callback]) Let us look at an example to understand how this method works. Example: In this example, we will use a URL to load the JavaScript file 'color.js' f
1 min read
How to use jQuery in Angular ? In this tutorial, we will learn how we can use jQuery with Angular. There are two ways in which we can use jQuery with Angular as discussed below: Table of Content By installing jQuery using the npm commandUsing jQuery CDN to use itBy installing jQuery using the npm commandYou can install the jQuery
2 min read