Reputation: 31
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.
Upvotes: 3
Views: 361
Reputation: 845
Use .offsetHeight
instead of .style.height
:
var h = Number(document.getElementById("worldMap").offsetWidth);
console.log(h);
Upvotes: 1