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

226
Views
can't access the 'header' element inside my html file using JS

I'm trying to create an HTML element using JavaScript document.createElement("div") and then prepend/append it in my header of the document, but below is what I'm getting.

enter image description here

enter image description here

enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You never defined header. You have to initialize it first by using var header = document.querySelector('header');

Then you can use header.prepend(...);

about 4 years ago · Juan Pablo Isaza Report

0

Try to replace your header.prepend to:

document.getElementsByTagName("header")[0].prepend(message);
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!