'Get button index on click, then click on another button using the index from previous one

I am trying to get the index from a button inside a div with multiple of the same button classes. Once that button is clicked the index is put in a variable and then another type of button is clicked using the index (ordering/number) from the previous one.

I can't really wrap my mind around how to do this. I tried the following but no luck.

$('.tab-link').on('click', function() {
  let tablinkIndex = $(this).index();
  $(".slider-dot tr:eq(" + tablinkIndex + ")").click();
});


Solution 1:[1]

I suggest you to use data-index for every element to find and determine indexes

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mostafa khoramnia