我目前在JavaScript中使用一个svg
元素。而且我是新手。
我的问题是,我有一个svg
元素,其中包含多个svg:g
元素。而在我的svg:g
元素中,我有各种其他的svg元素。
<svg>
<g class="my-class">
<g class "c1">
<text style="font-size: 9" x="0" y="-4"> john </text>
<text style="font-size: 9" x="70" y="-4"> 13 </text>
</g>
<g class="c2">
<text style="font-size: 9" x="0" y="-4"> john </text>
<text style="font-size: 9" x="70" y="-4"> 13 </text>
</g>
<g class="c3">
<text style="font-size: 9" x="0" y="-4"> john </text>
<text style="font-size: 9" x="70" y="-4"> 13 </text>
</g>
</g>
</svg>
我动态地在我的HTML中添加了g
元素。
g "my_class"
现在我想将我的svg
的宽度设置为g.my_class
的宽度。
var svgWidth = $('.my-class').width()
alert(svgWidth);
但是它给了我零。然而,我可以在浏览器中的黄色工具提示框中看到它
当我选择这一行时。
有没有人能够指导我? 我是否做对了,或者我如何实现这个目标? 谢谢