I want to Call the functions handleopenfirst()
and handlecloseall()
inside the init()
function.
If I do I get the Error:
Uncaught TypeError: this.handlecloseall is not a function at HTMLDivElement.<anonymous>
Thank you,
Here the JS Code:
class MLMenu {
constructor(menuEL){
this.MenuEl = menuEl;
this.buttonopenclose = this.MenuEl.querySelector("#buttonopenandclose");
this.navigationopen = false;
console.log(this.MenuEl)
console.log(this.buttonopenclose)
this.init();
}
init(){
//add Eventlistener to Open and Close Button
var button = this.buttonopenclose;
button.addEventListener('click', function(){
if (this.navigationopen === false) {
this.navigationopen = true;
button.classList.add('open');
button.classList.remove('close');
this.handleopenfirst();
console.log("Navigation should be opend now");
} else {
this.navigationopen = false;
button.classList.add('close');
button.classList.remove('open');
this.handlecloseall();
console.log("Navigation should be closed now");
}
});
}
handleopenfirst(){
console.log('hallo');
}
handlecloseall(){
console.log('hallo');
}
}