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

112
Views
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 answers
Answer question

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 Report

0

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

about 4 years ago · Juan Pablo Isaza Report

0

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

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!