I am not an expert in JS. I got that function working perfectly fine however it is not working in IE. I think it is because of the loop function using 'let' , then in the function querying the index of the current loop item... I understand this might no be supported in older browsers.
However I don't know how to achieve the same result without that part... I found this
var g = document.getElementById('my_div');
for (var i = 0, len = g.children.length; i < len; i++)
{
(function(index){
g.children[i].onclick = function(){
alert(index) ;
}
})(i);
}
from Get index of clicked element using pure javascript
but am not certain about how to use it. thanks for the help!
my function:
window.onload = function(){
const openers = document.querySelectorAll('.openerbuttons');
const fullsections = document.querySelectorAll('.fullsection');
for(let i = 0; i < openers.length; i++){
openers[i].addEventListener('click',function(){
if(!fullsections[i].classList.contains('inview')){
openers.forEach(function(opener) {
opener.classList.remove('opened');
});
fullsections.forEach(function(fullsectionjs) {
fullsectionjs.classList.remove('inview');
});
openers[i].classList.add('opened');
fullsections[i].classList.add('inview');
} else{
openers[i].classList.remove('opened');
fullsections[i].classList.remove('inview');
}
});
}
}