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

213
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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