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

229
Views
Canvas with a transparent background, why am i getting this error? Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

I have a canvas in HTML and I am trying to put a transparent background so I can layer other elements under it. This is the advised code to enable a transparent background on a canvas.

const canvas = document.getElementsByTagName('canvas');
document.body.appendChild(canvas);
const ctx = canvas.getContext("2d");

<canvas style="width: 1500px; height: 800px;"></canvas>

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

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

0

I believe that you are getting the error/exception due to the fact that getElementsByTagName returns a list instead of a single element.

I would propose/recommend using getElementById

A sample would be something like this:

HTML:

<canvas id='canvas' width='600' height='300'>
</canvas>

JS:

const canvas = document.getElementById('canvas');
const ctx = canvas.getContext("2d");
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!