Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda