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

210
Views
Change swiper-slide background (Swiper.js) when in darkmode, next.js + tailwindcss darkmode

I am using next.js with tailwindcss and Swiper js. I have also implemented a darkmode functionallity. So basically I want to change the background-color of all divs with the class of swiper-slide. I have some png images in every swiper slide and when i toggle the darkmode on I need the background of the swiper-slide to change. So I want to add the class of let say dark:bg-blue-900. I have tried grabbing the swiper-slides in useEffect by using querySelector all and then using a for of loop to add the classes, but the classes doesn't seem to be applied at all when I inspect the elements. How can I add the class? Here is my component

export default function VerticalSwiper() {
  const content = [
    { id: 1, img: PizzaImg },
    { id: 2, img: HamburgerImg },
    { id: 3, img: SteakImg },
    { id: 4, img: Salad1Img },
    { id: 5, img: WineImg },
    { id: 6, img: KebabImg },
    { id: 7, img: SodaImg },
    { id: 8, img: BeerImg },
    { id: 9, img: Salad2Img },
  ];

  useEffect(() => {
    const root = window.document.documentElement;
    if (root.classList.value === 'dark') {
      const swiperSlides = document.querySelectorAll('.swiper-slide');
      for (const swiperSlide of swiperSlides) {
        swiperSlide.classList.add('dark:bg-blue-900');
      }
    }
  });

  return (
    <div className="swiper-container">
      <Swiper
        direction={'vertical'}
        autoplay={{
          delay: 3500,
          disableOnInteraction: false,
        }}
        pagination={{
          clickable: true,
        }}
        modules={[Autoplay, Pagination]}
        className="mySwiper"
      >
        {content.map((item) => (
          <SwiperSlide key={item.id}>
            <SwiperContent img={item.img} />
          </SwiperSlide>
        ))}
      </Swiper>
    </div>
  );
}

about 4 years ago · Juan Pablo Isaza
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!