How to use jQuery Each Function in TypeScript ? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 the practical implementation make sure you have the latest version of jQuery installed into your current project. Use the below npm command to install jQuery in TypeScript. npm install jquerynpm install --save-dev @types/jqueryImport the jQuery into your current file using the below statement. import variable_name_by_which_you_want_to_import_jQuery from 'jquery'Example: The below code example explains how you can use the jQuery each() method in TypeScript. JavaScript //index.ts file import $ from "jquery"; declare var global: any; global.jQuery = $; import "jquery-ui"; $('.list-item').each(function () { $(this).on('click', function () { $('.result').text(` The ${$(this).text()} of the list was clicked!`) }) }); HTML <!-- index.html file --> <ul class="list"> <li class="list-item"> Item 1 </li> <li class="list-item"> Item 2 </li> <li class="list-item"> Item 3 </li> <li class="list-item"> Item 4 </li> <li class="list-item"> Item 5 </li> </ul> <p class="result"></p> Output: Example 2: The below example shows another practical use case of each method with TypeScript. JavaScript import $ from "jquery"; declare var global: any; global.jQuery = $; import "jquery-ui"; const arr: (number | string)[] = [1, 2, 3, "TypeScript", "GeeksforGeeks"]; $('#changeText').on('click', function () { $('.list-item').each(function (ind) { $(this).text (`Array item ${ind + 1} = ${arr[ind]}`); }); }) HTML <!-- index.html --> <ul class="list"> <li class="list-item"> Item 1 </li> <li class="list-item"> Item 2 </li> <li class="list-item"> Item 3 </li> <li class="list-item"> Item 4 </li> <li class="list-item"> Item 5 </li> </ul> <button id="changeText"> Change List Item Text </button> Output: Comment More infoAdvertise with us Next Article What is the use of .each() function in jQuery ? A abhish8rzd Follow Improve Article Tags : JQuery Similar Reads 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 What is the use of .each() function in jQuery ? The each() function in jQuery iterate through both objects and arrays. Arrays that have length property are traversed from the index 0 to length-1 and whereas arrays like objects are traversed via their properties names. Syntax: $.each('array or object', function(index, value){ // Your code }) In th 2 min read How to use jQuery with TypeScript ? 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 commandThe jQuery can be installed in your current TypeScript project folder using t 2 min read How to define jQuery function ? Defining the function in jQuery is different from JavaScript, the syntax is totally different. A function is a set of statements that takes input, do some specific computation and produce output. Basically, a function is a set of statements that performs some specific task or does some computation a 2 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 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 Like