javascript - firefox svg.getElementById('id') - Stack Overflow

I'm experimenting with interactive images. I've a jquery-ui slider bound to a function which

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
Add a ment  | 

3 Answers 3

Reset to default 5

I'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).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744938841a4602195.html

相关推荐

  • javascript - firefox svg.getElementById(&#39;id&#39;) - Stack Overflow

    I'm experimenting with interactive images. I've a jquery-ui slider bound to a function which

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信