I can't use the html elment with the id
notification-panel-sidebar
in my JavaScript, but I can Access it directly using jquery.
This is the Code:
const notificationContainer = {
elements: {
notificationPanelSidebar: $('#notification-panel-sidebar'),
notificationPanelSidebarContainer: $('#notification-panel-sidebar-container')
},
classes: {
notificationContainerActive: 'notification-container-active'
},
render () {
this.toggleNotificationContainer();
},
toggleNotificationContainer () {
console.log(this.elements.notificationPanelSidebar);
this.elements.notificationPanelSidebar.click((e) => { // this does not work
// $('#notification-panel-sidebar').click((e) => { // this works
let _this = $(e.currentTarget);
if (_this.hasClass(this.classes.notificationContainerActive)) {
console.log("+++++++");
this.hideNotificationContainer();
} else {
console.log("-------");
_this.addClass(this.classes.notificationContainerActive);
this.elements.notificationPanelSidebarContainer.show();
}
});
},
hideNotificationContainer () {
this.elements.notificationPanelSidebar.removeClass(this.classes.notificationContainerActive);
this.elements.notificationPanelSidebarContainer.hide();
}
}
$(document).ready(function () {
notificationContainer.render();
});
I get no error message.