3
votes
$('svg').height()

Just have stumbled upon an interesting bug (?) which appears in Mozilla when trying to get svg height. While you are trying to set through css SVG container size in percent, jQuery svg.height() will return not a pixel value, but a percent value.

Chrome works fine. Just open this fiddle in Mozilla Firefox and Chrome and compare results: http://jsfiddle.net/Ltew9pjb/3/

The answer for now, is simple, if SVG uses display:none, Mozilla Firefox for some reason will return percent value, and when there is no display: none, Mozilla will return px value. I don't know is it really a bug or not, but this how it works now. Check this fiddle: http://jsfiddle.net/Ltew9pjb/4/

So I want to ask is it a real Mozilla Firefox or jQuery bug, or something else?

1

1 Answers

2
votes

according to jQuery docs

The value reported by .height() is not guaranteed to be accurate when the element or its parent is hidden. To get an accurate value, ensure the element is visible before using .height(). jQuery will attempt to temporarily show and then re-hide an element in order to measure its dimensions, but this is unreliable and (even when accurate) can significantly impact page performance. This show-and-rehide measurement feature may be removed in a future version of jQuery.

So this is not a bug of any of them.