How to access SVG elements with Javascript

后端 未结 3 1807
野的像风
野的像风 2020-11-22 07:54

I\'m messing around with SVG and I was hoping I could create SVG files in Illustrator and access elements with Javascript.

Here\'s the SVG file Illustrator kicks ou

3条回答
  •  眼角桃花
    2020-11-22 08:37

    Is it possible to do it this way, as opposed to using something like Raphael or jQuery SVG?

    Definitely.

    If it is possible, what's the technique?

    This annotated code snippet works:

    
    
        
            SVG Illustrator Test 
        
        
    
            
    
            
        
    
    

    Note that a limitation of this technique is that it is restricted by the same-origin policy, so alpha.svg must be hosted on the same domain as the .html file, otherwise the inner DOM of the object will be inaccessible.

    Important thing to run this HTML, you need host HTML file to web server like IIS, Tomcat

提交回复
热议问题