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

215
Views
Change background color on carousel item change

I've spent hours on this and can't figure it out, so help would be appreciated.

I have a carousel that uses a foreach loop to create the items. One of the requirements, however, is that the div housing the carousel should have its color changed on the data used from the foreach.

<div class="p-0 col-lg-6 text-light d-none d-sm-block w-50 h-100">
  <div id="carousel" class="carousel d-flex flex-column justify-content-center align-items-center w-100 h-100 rounded bg-danger" data-bs-ride="carousel">
    <div class="carousel-inner justify-content-center" role="listbox">
      @foreach($marketingItems as $marketingItem)
        <div class="carousel-item text-center h-100 {{ $loop->first ? 'active' : '' }}">
          @if($marketingItem->image != null)
            <div class="item">
              <img src="{{get_marketing_image($marketingItem->image)}}"
                             alt="{{$marketingItem->image}}" class="img-thumbnail pb-5">
            </div>
          @endif

The above is an example of one item, I want to change the background color of the div id: carousel using my $marketingItem->bg_color and replace the bg-danger.

I found this:

 $("#carousel").on('slide.bs.carousel', function () {
   document.getElementById("carousel").style.backgroundColor = "red";
 });

But that doesn't seem to work... Please help! Thanks..

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Managed to figure it out, redid the css and managed to get it inside the box. Had some bootstrap stuff that was applying a margin and what not. Thanks for the help!

about 4 years ago · Juan Pablo Isaza Report

0

Try to change your js like :

$(document).ready(function(){
    $("#carousel").on('slide.bs.carousel', function () {
        document.getElementById("carousel").style.backgroundColor = "red";
    });
});
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!