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

298
Views
JavaScript TypeError: says a CSS declaration returns as "null"

Here is the code in question that seems to be causing issues:

        player.style.height = playerH + "px";
        function trackXY(){
        for(let i=0; i<pokeS.length; i++){
        let pokeS = document.getElementsByClassName('pikaStyle' + i);
        let xPlayer = parseInt(player.style.left + .5*player.style.width);
        let yPlayer = parseInt(player.style.top + .5*player.style.height);
        let xpokeS = parseInt(pokeS.style.left + .5*pokeS.style.width);
        let ypokeS = parseInt(pokeS.style.top + .5*pokeS.style.height);
        let rPlayer = .5*parseInt(player.style.height);
        let rpokeS = .5*parseInt(pokeS.style.height);
        let dX = xpokeS - xPlayer;
        let dY = ypokeS - yPlayer;
        let distance = Math.sqrt((dX*dX)+(dY*dY))
        if(distance <= (rpokeS+rPlayer)){
            alert("collison!" + pokeS.id);
        player.style.height = parseInt(player.style.height) + .5*parseInt(pokeS.style.height);
        }
      }
    }

it keeps either returning that "style" cannot be read or "left" is undefined. can someone advise? thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should use window.getComputedStyle() and getPropertyValue to get the style. You can't directly use element.style.height, it will return nothing.

The Window.getComputedStyle() method returns an object containing the values of all CSS properties of an element, after applying active stylesheets and resolving any basic computation those values may contain.

In your code, use:

window.getComputedStyle(player).getPropertyValue('height') 
window.getComputedStyle(pokeS).getPropertyValue('height')

Example:

let div = document.querySelector('div')
//return nothing
//console.log( div.style.height)
console.log(window.getComputedStyle(div).getPropertyValue('height'))
div{
height:50px;
}
<div></div>

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!