Recently, I've been developing a web project that requires a gallery with a slider below it. To tackle this issue, I have utilized the following JavaScript code within a forEach(element) function:
var divnumber = Array.from(element.parentNode.children).indexOf(element);
This approach allows the pagination to adjust based on the index of the selected element.
However, in order to ensure responsiveness and meet the specific requirements set by the graphic designer for the mobile view, I now need to retrieve the number of divs using their class names. Essentially, I need to work with the same array but containing different values.
Is there a modification that can be made to the above line of code to enable it to retrieve the index of an element based on its class rather than its parent? For additional context, refer to this pen: https://codepen.io/ridonibishi/pen/BaNyBva
I appreciate any assistance you can offer! Thank you.