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

295
Vistas
Class does not append on javascript appendChild() function

I have an onclick() event on a button, to execute te following code:

function digital_tour(){
    let loader = document.createElement("div");
    loader.className = "loader";
    console.log(loader);
    document.getElementById("main-div").appendChild(loader);
}

The code works, and the element loader is shown by the console.log and returns:

<div class="loader"></div>

The loader div get appended into the main-div, including the class, but my css style is not shown. My CSS code

.main-bg .loader{
    width: 100vw;
    position: absolute;
    top: 0;
    left: 0;
    height: 100vh;
    background-color: green;
    z-index: 5;
}

I want to show the CSS style to the loader div, but it does not work. What do I need to do to make this work?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

the CSS class works like this: .main-bg .loader means you should have an element with main-bg class which has an element with the .loader class inside in other words the CSS you have will only be applied to a loader class which is inside the element with main-bg class. but you are appending loader to main-div not main-bg.

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