Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!