Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

293
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda