views:

48

answers:

1

Hello,

I use SVG inisde my xhtml file. I can not get access to the text with id="Wert". What is wrong, I want to change the color form blue to red.

Untitled Page

<script type="text/javascript">
    function OnLoad() {
        setTimeout("timer()", 1000);
    }

    function timer() {
        var randomnumber = Math.floor(Math.random() * 101); // Zahlen von 0..100

        var svgdocument = document.svgid.getSVGDocument( 'svgid');
        svgtext = svgdocument.getElement.ById('Wert');
        svgtext.setattribute('style','fill:red');


        setTimeout("timer()", 1000);
    }
</script>

40

+3  A: 
  • function OnLoad() should be onload = function () (case sensitive!)
  • You should use setInterval instead of repeatedly calling setTimeout
  • You should pass it a function, not a string to be evaled
  • The getElementById method doesn't have a "." in it
  • The getElementById method only exists on the document object
  • You can't get an element using document.id_of_element except in some versions of IE (use getElementById instead)
  • setAttribute has a capital A in the middle of it
  • You should probably be using the NS versions of a lot of those methods since you seem to be working with a mixed namespace document
  • You shouldn't generate a random number if you aren't going to use it
David Dorward