【发布时间】:2015-10-21 05:37:57
【问题描述】:
html中有一个div如下:
<svg id="box" width="312" height="101"></svg>
我要获取svg标签的宽高:
var el = window.document.querySelector('#box');
但我无法通过el 获取宽度和高度,我该如何获取它们?
我使用 node.js 来运行脚本。整个代码是:
var jsdom = require('jsdom'),
content = '<svg id="box" width="300" height="120"></svg>';
jsdom.env({ features : { QuerySelector : true }, html : content,
done : function(errors, window) {
var w = window.document.querySelector('#box').attr("width");
console.log(w);
}
});
【问题讨论】:
-
你为什么不试试getElementById ?
-
@RobertLongson 是的,它做不到。
-
@dingo_d 此代码已在 jsdom.env() 中使用...
-
@RobertLongson TypeError: undefined is not a function...错误提示。
标签: javascript html svg