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

77
Vistas
Tabit.js multiple instances on same page with className

Using a tabs library called tabit.js. It initialises fine with ID and one tab but I've got multiple tabs now on one page and finding it difficult to make this work dynanically without fixing an ID for both. Thought about doing it as follows with each:

$('.tabs').each(function () {
  const element = $(this)
  const options = {
    buttonSelector: '[data-target]',
    buttonActiveClass: 'is-active',
    contentSelector: '[data-content]',
    buttonAttribute: 'data-target',
    contentAttribute: 'data-content',
    contentActiveClass: 'is-active',
  }
  if (element) {
    /* eslint-disable no-new */
    new Tabit(element, options)
  }
})

But Tabit implies it does not find a element initialise by outputting:

Uncaught TypeError: new Tabit requires a DOM element as its first argument.

View JSFiddle here: https://jsfiddle.net/e8y0d5um/7/

Any ideas how to make this work? Finding it very difficult to find any solutions of multiple tabs on the same page that don't have a unique ID.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

this in the each method refers to the DOM element. There is no need to wrap it in $(). Try this

$('.tabs').each(function () {
  const element = this
  const options = {
    buttonSelector: '[data-target]',
    buttonActiveClass: 'is-active',
    contentSelector: '[data-content]',
    buttonAttribute: 'data-target',
    contentAttribute: 'data-content',
    contentActiveClass: 'is-active',
  }
  if (element) {
    /* eslint-disable no-new */
    new Tabit(element, options)
  }
})
about 4 years ago · Juan Pablo Isaza Denunciar
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