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

226
Vistas
document.getElementById().style.backgroundImage works with file directory without folder but not with folder

I wrote a website last year using raw html, css, and js, but I've been attempting to rebuild my code with react as a good exercise to learn the tool. I've noticed that my old code to reset my backgroundImage no longer works if I use a local image directory within the url(...) pointer that contains a step into a folder, and only works with actual http:// urls or ones that do not contain a url; ex. url('image.png') or url('./image.png'). When the new code runs, the backgroundImage disappears if a local png is being used. I've been scratching my head for some time so I'd appreciate any help.

Old code:

function randombg(){
    var random= Math.floor(Math.random() * 2) + 1;
    var bigSize = ["url('background-images/1.png')",
                   "url('background-images/2.png')",
                   ...
    document.getElementById("random").style.backgroundImage=bigSize[random];
}

CSS:

#random {
    width: 100%;
    height: 100vh;
    background-image: url('assets/background-images/1.png');
    background-repeat: repeat; 
    position: absolute;
    z-index: -1;
}

New code is the same but uses a react function to run the js (handleClick(e) {...}).

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