I try to switch tabs. Created a class
export default class Tab {
constructor(tabSelector, handleClick) {
this._tabSelector = document.querySelector(tabSelector);
this._handleClick = handleClick;
}
_selectClick(e) {
function switchTab() {
const arrTab = Array.from(document.querySelectorAll('.tab-item'));
arrTab.forEach((item) => {
item.classList.remove('tab-item_selected');
})
}
switchTab();
e.currentTarget.classList.add('tab-item_selected');
this._handleClick();
}
setEventsListeners() {
this._tabSelector.addEventListener('click', this._selectClick);
}
}
I create an instance of a class. And give it a function:
const SearchString = document.querySelector('.search-link');
const btnRandom = new Tab('.tab-item_random', btnRandomClick);
function btnRandomClick() {
SearchString.classList.remove('search-link_opened');
}
btnRandom.setEventsListeners();
When I click the button "RANDOM" , then the class should be removed from the selector "search-link_opened".
But it doesn't happen.
btnRandomClick() is not executed. this._handleClick(); - undifined
I do not know why?