I have a jQuery project where I'm looping through a list of elements that all have the same class. What I need is for the 1st two elements class to be removed. Therefore I'm using the .removeClass() method. However, I don't know how to use that method and only remove the 1st two. It's moving all of them. Can someone help me without changing the direction of my code.
function putSiblingsInTableForEachH2() {
// line above sets function that will ultimately store siblings of each h2.toggler into a HTML table
var togglerHeaders = $("h2.toggler");
// line above sets variable togglerHeaders to all h2 elements with a class of ".toggler"
for (i = 0; i < togglerHeaders.length; i++) {
// line above: for loop that loops through array "togglerHeaders"
var currentH2Element = togglerHeaders[i];
// line above sets variable currentH2Element to togglerHeaders at position i
if (currentH2Element == togglerHeaders[0] || togglerHeaders[1]) {
$("h2").removeClass("toggler");
}
var siblingsofH2 = $(currentH2Element).nextUntil("h2.toggler");
// line above access siblings that are in h2.toggler element
// line says: set variable "siblingsofH2" to the current h2.toggler element you're on actual sibling elements but only siblings that are in between current element and next element that is "h2.toggler"
$(siblingsofH2).wrapAll("<table></table>");
// line above says: after correct sibling elements are stored to variable siblingsofH2 wrap elements in HTML table
} // line ends for loop
} // line ends function
putSiblingsInTableForEachH2();
// line above actually runs function