Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  57] [ 3]  / answers: 1 / hits: 23743  / 12 Years ago, fri, march 23, 2012, 12:00:00

Is there any accurate way to get the real size of a svg element that includes stroke, filters or other elements contributing to the element's real size from within Javascript?



I have tried pretty much everything coming to my mind and now I feel I'm coming to a dead end :-(



Updated question to add more context (Javascript)


More From » svg

 Answers
4

You can't get the values directly. However, you can get the dimensions of the bounding rectangle:


var el   = document.getElementById("yourElement"); // or other selector like querySelector()
var rect = el.getBoundingClientRect(); // get the bounding rectangle

console.log( rect.width );
console.log( rect.height);

It is supported at least in the actual versions of all major browser.


Check fiddle


[#86635] Thursday, March 22, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
taylert

Total Points: 627
Total Questions: 91
Total Answers: 108

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
taylert questions
;