I. Accessing the DOM of SVG in HTML
Code highlighting produced by Actipro Codehighlighter (freeware) http://www. Codehighlighter.com/--> 1 <! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
Ii. embedding JavaScript in SVG documents
Code highlighting produced by Actipro Codehighlighter (freeware) http://www. Codehighlighter.com/--> 1 <?xml version= "1.0" encoding= "UTF-8" standalone= "yes"? ><svg xmlns= "/http Www.w3.org/2000/svg "width=" 3.5in "height=" 1in "><title>listing 24-1 from the XML bible</title>< Script type= "Text/javascript" ><! [Cdata[alert (123);]] ></script><circle r= "" "cx=" cy= "style=" fill:red; Stroke:blue; Stroke-width:2 "/></svg>
Third, link the external JavaScript in the SVG document
Code highlighting produced by Actipro Codehighlighter (freeware) http://www. Codehighlighter.com/-->1 <?xml version= "1.0" encoding= "UTF-8" standalone= "yes"? ><svg xmlns= "/http/ Www.w3.org/2000/svg "xmlns:xlink=" Http://www.w3.org/1999/xlink "width=" 3.5in "height=" 1in "><title> Listing 24-1 from the XML bible</title><circle id= "x" r= "a" cx= "" cy= "" style= "fill:red; Stroke:blue; Stroke-width:2 "/><script type=" Text/javascript "xlink:href=" A.js "></script></svg>
Note that the namespace xmlns:xlink= "Http://www.w3.org/1999/xlink" needs to be added, otherwise the xlink:href= "A.js" attribute parsing the script node will error
Three ways to call SVG with HTML and JavaScript