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

185
Vistas
How to initialize a javascript slider only on certain web pages

I have a website with several pages. there is a Swiper slider on the homepage. all pages have a main.js file where the slider is initialized. how do I make sure that the other pages don't get an error in the console?
Error:
Uncaught ReferenceError: Swiper is not defined

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

0

Looking into the Swiper API, you can see that it uses a class called Swiper to initialize the slider.

Since you just want to validate if the Swiper class is present in your page, you can simple test it's type:

if (typeof Swiper != undefined) {
   const swiper = new Swiper('.swiper');
}
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