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

118
Vistas
i am trying to get the style of an element from html and trying to print on console

i am trying to get the style of an element from html and trying to print on console. I cant see style option while typing the style property in visual code. its keep showing the error Uncaught TypeError: Cannot read properties of null (reading 'style') in javascript var element; element = document.querySelector("#header").style.backgroudColor; console.log(element);

<!DOCTYPE html>
<html>

  <head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title>Page Title</title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link rel='stylesheet' type='text/css' media='screen' href='all.css'>
    <script src="javascript_code.js"></script>
  </head>

  <body>
    <div id="header" class="heading" style="background-color: red;">
      <h1>this is header</h1>
      <h1>this is header2</h1>
    </div>
    <script src="javascript_code.js"></script>
  </body>

  </html>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

you have included javascript file two time first in the header and second at the last inside body tag. first remove one of them and there is a spelling mistake in backgroundColor as you can see here element = document.querySelector("#header").style.backgroundColor = 'green';

about 4 years ago · Juan Pablo Isaza Denunciar

0

you can use document.getElementById('header').style.backgroudColor like this.

about 4 years ago · Juan Pablo Isaza Denunciar

0

i restarted the computer and all my snippets started working. the style property is now working.

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