Three ways to call SVG with HTML and JavaScript

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.