私は d3js を使用して、以下に示すコードの svg 要素の幅を見つけています。
<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>
しかし、それはこのエラーを返しました:
キャッチされていない TypeError: null のメソッド 'getPropertyValue' を呼び出せません
svg 変数は null 配列だと思います。
d3jsを使用してsvg要素の幅を取得するにはどうすればよいですか?