this is the start of a larger project but I'm running into an error as I test the basics on the frontend. The error is as follows
Uncaught TypeError: Cannot read property 'addClass' of undefined
at HTMLDivElement.openOverlay (live-search.js?ver=1.0:20)
at HTMLDivElement.dispatch (jquery.js?ver=1.12.4-wp:3)
at HTMLDivElement.r.handle (jquery.js?ver=1.12.4-wp:3)
This is the code I have so far, for the moment I'm just testing the trigger to open and close an overlay.
(function($) {
class Search {
constructor() {
this.openButton = $("#search-icon-btn");
this.closebutton = $(".search-overlay__close");
this.searchOverlay = $(".search-overlay");
this.events();
}
events() {
this.openButton.on("click", this.openOverlay);
this.closebutton.on("click", this.closeOverlay);
}
openOverlay() {
this.searchOverlay.addClass("search-overlay--active");
}
closeOverlay() {
this.searchOverlay.removeClass("search-overlay--active");
}
}
var liveSearch = new Search();
})(jQuery);
Any help would be much appreciated!