How to get id of a dynamic input field in javascript

I want to create a dynamic form where I also apply JavaScript to the dynamic elements.

What I want to do right now is figure out which field (stored in array or whatever data structure) in JavaScript has been clicked so that I can apply the script to that particular field.

The HTML looks like this:

<div class="triple">
  <div class="sub-triple">
    <label>Category</label>
    <input type="text" name="category" id="category" placeholder="Classes/Instances" required/>
    <ul class="cat-list"></ul>
  </div>
  <div class="sub-triple">
    <label>Relation</label>
    <input type="text" name="relation" id="relation" placeholder="Properties" required/>
    <ul class="rel-list"></ul>
  </div>
  <div class="sub-triple">
    <label>Value</label>
    <input type="text" name="value" id="value" placeholder="Classes/Instances" required/>
    <ul class="val-list"></ul>
  </div>
</div>

This “triple” div is dynamic and I want to create as many “triples” as the user wants, that also means the input fields of inside the “triple” section increase as well.

I’m confused on how to add javascript to one element of the input. For example I have inputs: category, relation and value and the user wanted 2 or more triples then the input ids could look like category2, relation2 and value2 or something similar to that.

let category = document.getElementById("category");

category.addEventListener("keyup", (e) => {
  removeElements();
  listDown(category, sortedClasses, ".cat-list")

});

If I lets say clicked on category2 for instance how do I tell that to my javascript since these fields are completely dynamic.

Summary: The user is adding repeat sections of triples (containing 3 input elements), where the id of each input element is generated dynamically. My script above works for the first triple section only as the ids are fixed, as for successive “triple” section the id of the fields get changed. How do I identify (see which element has been clicked) and get these dynamic ids