<script>
        
        
          
                Baseline
                
                  Widely available
                
                 *
              
        
        
        
          
                
              
                
              
                
              
        
        
      
      This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
* Some parts of this feature may have varying levels of support.
script は SVG の要素で、スクリプトを SVG 文書に追加することができます。
例
html
円をクリックすると色が変わります。
<svg
  viewBox="0 0 10 10"
  height="120px"
  width="120px"
  xmlns="http://www.w3.org/2000/svg">
  <circle cx="5" cy="5" r="4" />
  <script>
    // <![CDATA[
    function getColor() {
      const R = Math.round(Math.random() * 255)
        .toString(16)
        .padStart(2, "0");
      const G = Math.round(Math.random() * 255)
        .toString(16)
        .padStart(2, "0");
      const B = Math.round(Math.random() * 255)
        .toString(16)
        .padStart(2, "0");
      return `#${R}${G}${B}`;
    }
    document.querySelector("circle").addEventListener("click", (e) => {
      e.target.style.fill = getColor();
    });
    // ]]>
  </script>
</svg>
属性
crossorigin- 
この属性は、CORS 設定 を HTML の
<script>要素のように定義します。 値の型: [ anonymous | use-credentials ]?; 既定値:?; アニメーション: 可 hreftype- 
この属性は使用するスクリプト言語の型を定義します。 値の型:
<media-type>; 既定値:application/ecmascript; アニメーション: 不可 xlink:href非推奨;
使用可能な場所
| カテゴリー | 無し | 
|---|---|
| 許可されている内容 | あらゆる要素や文字データ | 
仕様書
| Specification | 
|---|
| Scalable Vector Graphics (SVG) 2> # ScriptElement>  | 
            
ブラウザーの互換性
Loading…