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

142
Vistas
How to add specfic elements to to HTML containers using DOM

I'm doing the Odin Project and am stuck on an exercise.

The requirement is that I have to add specific elements to a container in the HTML file but I can't get the following sections to show up at all when I run it:

a <div> with a black border and pink background color with the following elements inside of it:

another <h1> that says “I’m in a div” a <p> that says “ME TOO!”

Hint for this one: after creating the <div> with createElement, append the <h1> and <p> to it before adding it to the container.

Here's my code https://codepen.io/mohd057/pen/KKQWdYV

const container = document.querySelector('#container');

const myP = document.createElement("p");
myP.style.color = "red"; 
myP.textContent = "Hey I'm red!"; 

const myH = document.createElement("h3")
myH.style.color = "blue"; 
myH.textContent = "I'm a blue h3!"; 

container.appendChild(myP);

container.appendChild(myH);

const myDiv = document.createElement("div"); 
myDiv.setAttribute('style', 'border: black; background: pink;'); 

    const anotherH = document.createElement("h1"); 
    anotherH.textContent = "I'm in a div"; 
    const anotherP = document.createElement("p"); 
    anotherP.textContent = "ME TOO!"; 

    container.appendChild(myDiv);

Here's the link to the exercise https://www.theodinproject.com/lessons/foundations-dom-manipulation-and-events (struggling on questions 3, 1, and 2 are fine)

Would love to know where I'm going wrong.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

What is missing:

  • border needs a border-style property to show
  • background's color property is called background-color otherwise you have to define it like this
  • You didn't append any element inside myDiv
const container = document.querySelector('#container');

const myP = document.createElement("p");
myP.style.color = "red"; 
myP.textContent = "Hey I'm red!"; 

const myH = document.createElement("h3")
myH.style.color = "blue"; 
myH.textContent = "I'm a blue h3!"; 

container.appendChild(myP);

container.appendChild(myH);

const myDiv = document.createElement("div"); 
myDiv.setAttribute('style', 'border: black solid; background-color: pink;'); 

    const anotherH = document.createElement("h1"); 
    anotherH.textContent = "I'm in a div"; 
    const anotherP = document.createElement("p"); 
    anotherP.textContent = "ME TOO!"; 

    myDiv.appendChild(anotherH);
    myDiv.appendChild(anotherP);
    container.appendChild(myDiv);
about 4 years ago · Santiago Gelvez 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