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

159
Visualizações
Unable to return node element by function call
function createContent() {
  const mainContent = document.querySelector("#content");
  return mainContent;
}
function renderSite() {
  createContent();
  mainContent.appendChild(createHeader());
  mainContent.appendChild(createMain());
}

Whenever I run renderSite, I get an error telling me mainContent is not defined. I can fix this by adding mainContent manually to renderSite. But why am I unable to return mainContent when calliing createContent() from renderSite()?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

mainContent is in the createContent() function scope. If you want to use it this way, you need not just to run it, but assign the result of function execution like that:

function renderSite() {
  const mainContent = createContent();
  mainContent.appendChild(createHeader());
  mainContent.appendChild(createMain());
}
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