I have problems doing a getElementById() on an anchor tag in SVG.
The following example illustratres the problem:
http://www.carto.net/neumann/temp/update_anchor_tag.svg
Is this a known issue or am I doing something wrong? It works fine in
Batik, ASV and Opera 9 preview.
Thanks for any information on this,
Andreas
This might be due to Mozilla using XBL to implement it...
--
Björn Höhrmann · mailto:bjo...@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Andreas Neumann wrote:
> I have problems doing a getElementById() on an anchor tag in SVG.
>
> The following example illustratres the problem:
> http://www.carto.net/neumann/temp/update_anchor_tag.svg
>
> Is this a known issue or am I doing something wrong?
I don't think you are doing something wrong and searching bugzilla for
getElementById or SVG has not brought up anything. Therefore I have filed
<https://bugzilla.mozilla.org/show_bug.cgi?id=320724>
--
Martin Honnen
http://JavaScript.FAQTs.com/
>The following example illustratres the problem:
>http://www.carto.net/neumann/temp/update_anchor_tag.svg
>
>Is this a known issue or am I doing something wrong? It works fine in
>Batik, ASV and Opera 9 preview.
I think the reason is the a implementation as XBL binding (outside the SVG
DOM) and not as SVGAElement, see:
<http://developer.mozilla.org/en/docs/SVG_in_Firefox_1.5>
cu, Thomas
--
SVG - Learning By Coding
<http://svglbc.datenverdrahten.de/>
Is there any workaround to be able to change the URL of an anchor tag
in Mozilla SVG? Maybe by removing the old link and adding a new one? Or
using some XBL stuff? I am new to XBL, haven't used it at all, so far
...
Andreas
>Is there any workaround to be able to change the URL of an anchor tag
>in Mozilla SVG?
Set an ID for the rect element:
<a xlink:href="http://www.google.com/">
<rect id="myRect" x="50" y="50" width="50" height="50" fill="red"/>
</a>
<text x="120" y="50" onclick="updateLink()">
Click to update link on red rectangle</text>
and use this line in your function to access the a element object:
document.getElementById("myRect").parentNode.setAttributeNS(xlinkNS,"href","http://www.w3.org/");
Works for me with FF 1.5 and ASV too.
Andreas Neumann wrote:
> Is there any workaround to be able to change the URL of an anchor tag
> in Mozilla SVG?
You can access the element with e.g.
var aElement =
document.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'a')['a1'];
where 'a1' is the id attribute value. Then you should be able to use the
Core DOM to change the attribute value of the xlink:href attribute e.g.
if (aElement != null) {
aElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href',
'http://www.mozilla.com/');
Right on the nose. :(
-Boris