Nos bénévoles n'ont pas encore traduit cet article en Français. Aidez-nous à réaliser cette tâche !
A SVG script
element is equivalent to the script
element in HTML and thus is the place for scripts (e.g., ECMAScript).
Any functions defined within any script
element have a global scope across the entire current document.
Usage context
Categories | None |
---|---|
Permitted content | Any elements or character data |
Example
The following code snippet demonstrates the use of the SVG script
tag. In this code, we use JavaScript to change the radius of the SVG <circle>
element.
<svg width="100%" height="100%" viewBox="0 0 100 100" xmlns="https://www.w3.org/2000/svg"> <script type="text/javascript"> // <![CDATA[ function change(evt) { var target = evt.target; var radius = target.getAttribute("r"); if (radius == 15) { radius = 45; } else { radius = 15; } target.setAttribute("r",radius); } // ]]> </script> <circle cx="50" cy="50" r="45" fill="green" onclick="change(evt)" /> </svg>
Live result:
Attributes
Global attributes
Specific attributes
DOM interface
This element implements the SVGScriptElement
interface.
Specifications
Specification | Status | Comment |
---|---|---|
Scalable Vector Graphics (SVG) 2 The definition of '<script>' in that specification. |
Candidate Recommendation | |
Scalable Vector Graphics (SVG) 1.1 (Second Edition) The definition of '<script>' in that specification. |
Recommendation | Initial definition |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 1.0 | 1.5 (1.8) | 9.0 | 9.0 | 3.0.4 |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 3.0 | 1.0 (1.8) | No support | (Yes) | 3.0.4 |
The chart is based on these sources.