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

240
Views
TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. Did i do anything wrong?

I'm trying to make a h1 with JavaScript and it gives me this error:

TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

The code:

function append(child) {
  document.body.appendChild(child);
};

const title = React.createElement(
  'h1',
  null,
  'Hello World',
);
append(title);
console.log(header);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

React elements are not DOM elements, so you can't use them with appendChild.

You'll want to either use the DOM directly or use React, but usually not both (or at least, typically in a React project the amount of direct DOM manipulation you do is fairly minimal).

Here's that code using the DOM (no React):

function append(child) {
    document.body.appendChild(child);
}

const title = document.createElement("h1");
title.textContent = "Hello world";
append(title);
console.log(title); // Changed `header` to `title`, you have no `header` element in the code

Doing the same with React, you wouldn't typically have an append function like yours. You'd have a single call to ReactDOM.render in the entire project (usually) that mounted your top-level React component in a DOM element; everything else would be rendered by React as part of handling the component logic.

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!