firefox svg.getElementById('id')

2

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 comment (i'm using id's the proper way):

<svg xmlns="http://www.w3.org/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>
javascript
firefox
svg
asked on Stack Overflow Nov 9, 2011 by dr jerry • edited Nov 9, 2011 by dr jerry

3 Answers

5

I've just implemented svg.getElementById in Firefox. It will appear in Firefox 11.

answered on Stack Overflow Nov 9, 2011 by Robert Longson • edited Nov 9, 2011 by William
3

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 ...");
answered on Stack Overflow Jan 1, 2012 by Silas Hansen
2

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 common method Element.prototype.getElementById exists; there's just HTMLDocument.prototype.getElementById).

answered on Stack Overflow Nov 9, 2011 by duri • edited Nov 9, 2011 by duri

User contributions licensed under CC BY-SA 3.0