Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getElementById on an anchor tag

5 views
Skip to first unread message

Andreas Neumann

unread,
Dec 18, 2005, 6:54:51 AM12/18/05
to
Hi,

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

Bjoern Hoehrmann

unread,
Dec 18, 2005, 11:01:00 AM12/18/05
to
* Andreas Neumann wrote in netscape.public.mozilla.svg:

>I have problems doing a getElementById() on an anchor tag in SVG.

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/

Martin Honnen

unread,
Dec 18, 2005, 12:11:06 PM12/18/05
to

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/

Thomas Meinike

unread,
Dec 18, 2005, 12:28:30 PM12/18/05
to
Andreas Neumann wrote:

>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/>

Andreas Neumann

unread,
Dec 18, 2005, 12:35:31 PM12/18/05
to
thanks - I cced that bug.

Andreas Neumann

unread,
Dec 18, 2005, 12:52:02 PM12/18/05
to
ok, I see.

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

Thomas Meinike

unread,
Dec 18, 2005, 1:59:30 PM12/18/05
to
Andreas Neumann wrote:

>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.

Martin Honnen

unread,
Dec 18, 2005, 1:51:27 PM12/18/05
to

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/');

Boris Zbarsky

unread,
Jan 3, 2006, 10:22:50 PM1/3/06
to
Thomas Meinike wrote:
> I think the reason is the a implementation as XBL binding (outside the SVG
> DOM) and not as SVGAElement

Right on the nose. :(

-Boris

0 new messages