PETER wrote:
>
>I have looked every where for correct use of "getElementById" but cannot see 
>what I am doing wrong !!
>
>
>Please have a look at http://www.sst-svg.co.uk/devtest2.svg
>In FIREFOX
>
>
>
>I really cannot see what is wrong - why is it returning Null ??

It's returning null because the vars the SVG is not rendered at the point at 
which the vars are being assigned.  There are a number of ways you could solve 
that problem.  You could wrap up the variable assignments in an onload() 
function like this:

<svg xmlns="http://www.w3.org/2000/svg"; version="1.1" onload="findthings()">


  <script type="text/javascript">
  <![CDATA[

var elthingtochange;
var elthingtochange2;

function findthings() 
{
elthingtochange = document.getElementById('thingtochange');
elthingtochange2 = document.getElementById('thingtochange2');
}

etc.

Another, simpler way to do that would be to pass an event.  In that case, the 
code might look something like this:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd";>

<svg xmlns="http://www.w3.org/2000/svg"; version="1.1">


  <script type="text/javascript">
  <![CDATA[

function dochange(evt)
{
        elthingtochange = evt.target;
        elthingtochange.setAttribute( "fill", "blue" );
}

  ]]>
  </script>


  <circle id="thingtochange" onclick="dochange(evt)" cx="100" cy="50" r="40" 
stroke="black"
  stroke-width="2" fill="red" />

  <circle id="thingtochange2" onclick="dochange(evt)" cx="300" cy="50" r="40" 
stroke="black"
  stroke-width="2" fill="green" />
</svg> 

Notice that both functions call the same function, but the evt.target allows 
the function to tell which object fired the event.

Ed


------------------------------------

-----
To unsubscribe send a message to: [email protected]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my 
membership"
----Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/svg-developers/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/svg-developers/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Reply via email to