getBBox() returns nothing for rect or path
Asked Answered
J

1

2

Please refer below rect code.

<rect id="container_svg_ChartArea" x="146.8" y="20" width="633.2" height="414" fill="White" stroke-width="1" stroke="Gray"></rect>

i tried get the rectangle bounding box value it returns nothing i.e."0" for x=0,y=0,width=0,height=0

$("#container_svg_ChartArea")[0].getBBox()

but when i get the attribute for x/y/width/height it returns some value

$("#container_svg_ChartArea").attr("x") ->value returned.

same for path element as well as rectangle element.

what is going wrong?

no solution provide here.

how to get bounding box or rect (getBBox()) for svg path in jquery

thats why i created another thread. it is not duplicate thread.

Thanks,

Siva

Joviality answered 6/5, 2013 at 6:44 Comment(4)
possible duplicate of how to get bounding box or rect (getBBox()) for svg path in jqueryTurboelectric
Please provide a jsfiddle with your bug, your code works correctly for me: jsfiddle.net/duopixel/UdLtxSilverside
i want to get the rectangle or box for grouped svg path. please refer below jsfiddle. jsfiddle.net/gFJyCJoviality
document.querySelector("#container_svg_ChartArea").getBBox();Synodic
I
0

Look this example on how to get and manage the bounding box of svg elements

http://www.janvas.com/illustrators_designers_developers/projects/janvas2D_web/examples_EN.php?exampleName=ufo_animation_EN

in general

var svgElement = document.getElementById('the id of your element');
bbox = svgElement.getBBox();

console.log( bbox.x ) ;
console.log( bbox.y ) ;
console.log( bbox.width ) ;   
console.log( bbox.height ) ; 
Ibo answered 7/5, 2013 at 22:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.