Re: does document.getElementId("MyElementId") work?

Hi,

I think your problem is that, unlike with javascript and html,
the 'document' object is undefined.  You need to define it yourself
when the svg is loaded or just use the DOM2 Event interface:

	<svg width="100" height="100">
	    <script><![CDATA[
	    function MouseClickHandler(evt) {
	      var obj = evt.target;
	        if (obj == null) {
	          alert("Obj is a null!");  
	        } else {
	          obj.setAttribute('r', '20');
			}
	    }
	  ]]></script>
	  <circle id="MyElement" cx="50" cy="50" r="10"
		onclick="MouseClickHandler(evt)"/>
	</svg>

This will work with the Adobe plugin and IE 5.5.  I don't know
why, but Netscape 4.7 doesn't seem to like it (indeed, Netscape
crashes with an 'illegal operation' error.)

See the SVG/Interactivity and DOM2/Events pages for more
information.

HTH,
ERic


>Message-ID: <20001001204420.27562.qmail@web310.mail.yahoo.com>
>Date: Sun, 1 Oct 2000 13:44:20 -0700 (PDT)
>From: Wu Ping <wupingzj@yahoo.com>
>To: www-svg@w3.org
>Subject: does document.getElementId("MyElementId") work?
>
>Dear sir,
>
>I try to use the following code to get the reference
>of an element in a svg file, but always get the null
>result. Could you give me a tip?
>
><svg width="100" height="100">
>  <defs><script><![CDATA[
>    function MouseClickHandler() {
>      var obj;
>        obj = document.getElementById('MyElement');
>        if (obj == null)
>          alert("Obj is a null!");
>        else
>          obj.setAttribute('r', '20');
>        }
>  ]]></script>
>  </defs>
>  <circle id="MyElement" cx="50" cy="50"
>onclick="MouseClickHandler()" r="10"/>
></svg>
>
>I run it with IE5 and adobe svg viewer.
>
>Thank you in advance!
>
>W P

Received on Sunday, 1 October 2000 20:19:54 UTC