How to run the same function on different sections on a page with same class name

How to run the same function on different sections on a page with same class name

I have function that is calculating the difference between two fields and showing it in the third field. This is working fine. How can I run the same function if I have multiple "mysection" in my html to calculate the difference between fields within each of these sections?

I have function that is calculating the difference between two fields and showing it in the third field. This is working fine. How can I run the same function if I have multiple "mysection" in my html to calculate the difference between fields within each of these sections?

$(document).ready(function(){
    var total=$(".field2");
    total.keyup(function(){
    var diff = Number($(".field2").val()) - Number($(".field1").val());    
   $(".field3").val(diff.toFixed(2));
    });    
    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="mysection">
    <input type="text" name="field1" value="" size="30" maxlength="300" class="field1">
    <input type="text" name="field2" value="" size="30" maxlength="300" class="field2">
    <input type="text" name="field3" value="" size="30" maxlength="300" class="field3">
    </div>


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Understand and Use JavaScript's .forEach() vs. jQuery's .each()

There are two functions to deal with an array on the client-side – JavaScript's .forEach() and jQuery's .each(). Here, I will teach you how to use both of these methods with some sample code.

jQuery vs Vanilla JavaScript - Beau teaches JavaScript

When should you use jQuery instead of vanilla JavaScript? Is jQuery still relevant? What is jQuery good for? jQuery vs vanilla JavaScript - Beau teaches JavaScript

3 JavaScript libraries to replace jQuery

Ubiquitous jQuery has been outmoded by JavaScript and browser advances. Cash, Zepto, and Syncfusion are three JavaScript libraries picking up where jQuery left off