I am having some issue with getting width of <g></g>
element using jQuery. Using .innerWidth()
or width()
returns me null. Is it possible to get the <g></g>
width using jquery?
I am asking this, because of rendering differences between Chrome and IE. In chrome I simply use:
var box = svg.node().getBBox();
var width = box.width;
But in IE it doesnt work - it returns the widht of 0.
Add Id to element Maybe work
<svg viewBox="0 0 95 50"
xmlns="http://www.w3.org/2000/svg">
<g stroke="green" fill="white" stroke-width="5" id="myGroup">
<circle cx="25" cy="25" r="15"/>
<circle cx="40" cy="25" r="15"/>
<circle cx="55" cy="25" r="15"/>
<circle cx="70" cy="25" r="15"/>
</g>
</svg>
<script>
$(document).ready(function(){
var height = document.getElementById("myGroup").getBBox().height;
var width = document.getElementById("myGroup").getBBox().width;
alert(" width "+width+" height "+height);
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.