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

355
Vistas
Why does prepend() javascript method not work?

I'm practicing with DOM manipulation in JavaScript following a course.

I wriote the same code as the guy of the course but it doesn't work. The code should create an html element and add it to the DOM and it does, but the element is not showing in the page. Besides, if I open the inspector tool the element is there but is greyed out like when you put display:none ... it's invisible... enter image description here

const header = document.querySelector('.header');
const message = document.createElement('div');
message.classList.add('cookie-message');
message.innerHTML =
  'We use cookies for improved functionality and analytics. <button class="btn btn--close-cookie">Got it!</button>';
header.prepend(message);
.header {
  padding: 3em;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cookie-message {
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  width: 100%;
  background-color: white;
  color: #bbb;
  font-size: 1.5rem;
  font-weight: 400;
}
<!DOCTYPE html>
<html lang="en">
  <head>
  </head>
  <body>
    <header class="header">
    
    </header>
   </body>
   </html>

I am using FireFox as browser and I saw on MDN documentation about Element.prepend() that it is fully supported by FireFox but for me is not working...

Then I tried on Chrome and it works.

enter image description here

Someone can help me out? Am I missing something?

about 4 years ago · Juan Pablo Isaza
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