Skip to content
Related Articles

Related Articles

Improve Article

SVG <script> Element

  • Last Updated : 27 Oct, 2020

SVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas.

The SVG <script> element allows adding scripts to an SVG document.

Syntax:

<script>
    // Script Here 
</script>

Attributes:

  • crossorigin: This defines the COS settings.
  • href: This defines the href URL to load.
  • type: Type of language or script to use.
  • Global Attributes: Some global attributes used like core attributes and styling attributes, etc.

Example 1:






<!DOCTYPE html>
<html>
  
<body>
    <svg width="400" height="200"
        xmlns="http://www.w3.org/2000/svg">
        <script type="text/javascript">
            alert("GeeksforGeeks"); 
        </script>    
    </svg>
</body>
  
</html>

Output:

Example 2:




<!DOCTYPE html>
<html>
  
<body>
    <svg width="400" height="200"
        xmlns="http://www.w3.org/2000/svg">
        <script>
            console.log(
"GeeksforGeeks: Computer Science Portal for Geeks"); 
        </script>    
    </svg>
</body>
  
</html>

Output:

Supported Browsers: The following browsers are supported by this SVG element:

  • Chrome
  • Edge
  • Firefox
  • Safari
  • Internet Explorer
  • Opera

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :