Accessing SVG inside HTML
I am using SVG inisde my xhtml file. I cannot access the text with id = "Wert". What is wrong, I want to change the color shape from 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
+2
a source to share
1 answer
-
function OnLoad()
should beonload = function ()
(case sensitive!) - You should use
setInterval
instead of multiple callsetTimeout
- You must pass a function to it, not a string to be imposed
- The getElementById method does not have a "." in him
- The getElementById method only exists for the document object
- You cannot get the element using
document.id_of_element
except some versions of IE (use getElementById instead) -
setAttribute
has capital A in the middle of it - You should probably use NS versions of many of these methods as you seem to be working with a mixed namespace document
- You shouldn't be generating a random number if you're not going to use it.
+5
a source to share