Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
function is undifined js. Call context lost

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!