admin管理员组文章数量:1406943
I'm experimenting with interactive images. I've a jquery-ui slider bound to a function which updates the path inside an svg document (embedded in a web page).
I'm trying to retrieve the path with:
document.getElementsByTagName('svg')[0].getElementById('me').setAttribute('d', "M 30 30 ...)
This is working fine in Chrome and Safari, but not in Firefox (where I have to use getElementsByClassName(..)[0]
. Is there something I'm missing, or is id
as attribute not allowed in an svg document?
BTW I checked on the last release of Firefox 8.0
Just saw now an message in the console:
Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIDOMSVGSVGElement.getElementById]
Would have been nice if this was indicated as a normal script error.
As per first ment (i'm using id's the proper way):
<svg xmlns="" version="1.1" height="370" width="400" baseProfile="full" viewbox="0 0 1000 1000">
<g stroke="black" stroke-width="8" fill="black" transform="scale(4)">
<path id="me" d="" class="classme"/>
</g>
</svg>
I'm experimenting with interactive images. I've a jquery-ui slider bound to a function which updates the path inside an svg document (embedded in a web page).
I'm trying to retrieve the path with:
document.getElementsByTagName('svg')[0].getElementById('me').setAttribute('d', "M 30 30 ...)
This is working fine in Chrome and Safari, but not in Firefox (where I have to use getElementsByClassName(..)[0]
. Is there something I'm missing, or is id
as attribute not allowed in an svg document?
BTW I checked on the last release of Firefox 8.0
Just saw now an message in the console:
Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIDOMSVGSVGElement.getElementById]
Would have been nice if this was indicated as a normal script error.
As per first ment (i'm using id's the proper way):
<svg xmlns="http://www.w3/2000/svg" version="1.1" height="370" width="400" baseProfile="full" viewbox="0 0 1000 1000">
<g stroke="black" stroke-width="8" fill="black" transform="scale(4)">
<path id="me" d="" class="classme"/>
</g>
</svg>
Share
Improve this question
edited Nov 9, 2011 at 14:09
dr jerry
asked Nov 9, 2011 at 12:45
dr jerrydr jerry
10k25 gold badges85 silver badges127 bronze badges
1
- Perhaps the following link helps? codingforums./showthread.php?t=94475 – Ben van Gompel Commented Nov 9, 2011 at 12:52
3 Answers
Reset to default 5I've just implemented svg.getElementById
in Firefox. It will appear in Firefox 11.
If you dont mind using jQuery, I have just tested with version 1.7.1 and svg dom traversal seems to work just perfectly:
$("svg:first").find("#me").attr("d", "M 30 30 ...");
Element nodes don't have getElementById
method. This is understandable as ID should be unique across the whole document. Use document.getElementById('me')
.
Note that Firefox doesn't support getElementById
even on HTML elements (means that no mon method Element.prototype.getElementById
exists; there's just HTMLDocument.prototype.getElementById
).
本文标签: javascriptfirefox svggetElementById(39id39)Stack Overflow
版权声明:本文标题:javascript - firefox svg.getElementById('id') - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744938840a2633357.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论