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

181
Views
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 answers
Answer question

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 Report
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!