Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda