I am implementing a function in jQuery to toggle an 'active' class on elements within a grid. Here is the code snippet:
$(".cinema-seats .seat").on("click", function () {
$(this).toggleClass("active");
}
Essentially, when clicking on random boxes in a 3x3 grid, they are assigned the 'active' class. What I aim to achieve next is to determine the index of these active boxes in relation to the original grid.
For instance,
box 1(active) box2 box3
box 4 box5(active) box6
box 7 box8 box9
The expected output would be 1,5 as they represent the indexes of the active classes within the grid.
This is just a simple illustration; my ultimate goal is to replicate this behavior in a larger 7x14 grid, organized into rows and columns, with all elements sharing the common class '.seats'. Once again, the objective is to retrieve the index (n-th child) of the active boxes with respect to all seats.
View the project on Codepen - https://codepen.io/divi7/pen/zYvbbVN