Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  70] [ 4]  / answers: 1 / hits: 50709  / 11 Years ago, thu, october 31, 2013, 12:00:00

I am using d3js to find the width of an svg element the code given below:



<script>
var body = d3.select(body);
console.log(body);
var svg = body.select(svg);
console.log(svg);
console.log(svg.style(width));
</script>

<svg class=svg height=3300 width=2550>
<image x=0 y=0 height=3300 width=2550 xlink:href=1.jpg></image>
<rect class=word id=15 x=118 y=259 width=182 height=28
text=Substitute></rect>
</svg>


But it returned this error:




Uncaught TypeError: Cannot call method 'getPropertyValue' of null




I think, the svg variable is a null array.



How can I get the width of an svg element using d3js?


More From » svg

 Answers
25
<svg class=svg height=3300 width=2550>
<image x=0 y=0 height=3300 width=2550 xlink:href=1.jpg></image>
<rect class=word id=15 x=118 y=259 width=182 height=28
text=Substitute></rect>
</svg>

<script>
var body = d3.select(body);
console.log(body);
var svg = body.select(svg);
console.log(svg);
console.log(svg.style(width));
</script>


Just place your script after svg element is loaded by the browser and all will be fine.


[#74580] Wednesday, October 30, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
amberlykaliac

Total Points: 415
Total Questions: 100
Total Answers: 85

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
;