Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
p5.js parent() | Uncaught (in promise) TypeError: Cannot read properties of null (reading 'appendChild')

I do exactly as the library docs here.

I have an error

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'appendChild')

index.html

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="styles/index.css" />
        <script src="libs/p5.min.js"></script>
        <script src="scripts/barcode.js"></script>
    </head>
    <body>
        <div class="container"></div>
    </body>
</html>

Tried defer on the barcode script import, and putting it in the end.

barcode.js

function setup() {
    let cnv = createCanvas(500, 500);
    cnv.parent("container");
}

Tried this, nothing changed

async function setup() {
        let cnv = await createCanvas(500, 500);
        cnv.parent("container");
}

Thanks for your insight !

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As the p5 documentation says:

The parent() function is used to attach the element as a parent element.

This function accepts either a string ID, DOM node, or p5.Element Add

So add an id to container div and pass it to parent instead of class fix the problem

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="styles/index.css" />
        <script src="libs/p5.min.js"></script>
        <script src="scripts/barcode.js"></script>
    </head>
    <body>
        <div id="container"></div>
    </body>
</html>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda