Have a class:
'use strict'
class modal{
modal_wnd;
close;
constructor(){
this._init();
}
_init(){
this.modal_wnd = document.getElementById('modal'); //div
this.close = document.getElementById('mdl_close'); // span 'X'
this.close.addEventListener('click', this.close_1);
}
show(){
this.modal_wnd.style.visibility = 'visible';
}
close_1(){
alert(this.close);
this.modal_wnd.style.visibility = 'hidden';
}
}
Have div-element 'modal' and span 'X' in it. On a page have a button to show div:
bt_modal.addEventListener("click", function(){
let mdl = new modal();
mdl.show();
});
that works fine, but when I press 'X' - get such an error: Uncaught TypeError: Cannot read properties of undefined (reading 'style') at HTMLSpanElement.close_1. Can anyone explain why does it happen?