3

I cannot get the object's height in js code. My HTML code:

<!DOCTYPE html>
<html lang="en">
    <body>
      <object onload="loadMarkers()" type="image/svg+xml" data="WorldMap.svg" id="worldMap"></object>
      <script src="project.js"></script>
    </body>
</html> 

JS code (the name of the file in HTML is right, I checked it):

function loadMarkers() {
    var h = document.getElementById("worldMap").style.height;
    console.log(h);
}

The console output is an empty line. If I write

var h = Number(document.getElementById("worldMap").style.height);
console.log(h);

the output is 0.

1 Answers1

1

Use .offsetHeight instead of .style.height:

var h = Number(document.getElementById("worldMap").offsetWidth);
console.log(h);
Martin Osusky
  • 820
  • 1
  • 6
  • 15