---
title: SVGElement
slug: Web/API/SVGElement
translation_of: Web/API/SVGElement
---
<div>{{APIRef("SVG")}}</div>

<div>所有SVG DOM类的父类.</div>

<div> </div>

<p>{{InheritanceDiagram}}</p>

<h2 id="属性">属性</h2>

<dl>
 <dt>{{domxref("SVGElement.dataset")}}{{readonlyInline}}</dt>
 <dd>A {{domxref("DOMStringMap")}} object which provides a list of key/value pairs of named data attributes which correspond to <a href="/en-US/docs/Web/Guide/HTML/Using_data_attributes">custom data attributes</a> attached to the element. These can also be defined in SVG using attributes of the form {{SVGAttr("data-*")}}, where <code>*</code> is the key name for the pair. This works just like HTML's {{domxref("HTMLElement.dataset")}} property and HTML's {{htmlattrxref("data-*")}} global attribute.</dd>
 <dt>{{domxref("SVGElement.id")}}{{readonlyInline}}</dt>
 <dd>A {{domxref("DOMString")}} representing the value of the {{SVGAttr("id")}} attribute on the given element, or the empty string if <code>id</code> is not present.</dd>
 <dt>{{domxref("SVGElement.xmlbase")}}{{readonlyInline}}</dt>
 <dd>A {{domxref("DOMString")}} corresponding to the {{SVGAttr("xml:base")}} attribute on the given element.</dd>
 <dt>{{domxref("SVGElement.ownerSVGElement")}}{{readonlyInline}}</dt>
 <dd>An {{domxref("SVGSVGElement")}} referring to the nearest ancestor {{SVGElement("svg")}} element. <code>null</code> if the given element is the outermost <code>&lt;svg&gt;</code> element.</dd>
 <dt>{{domxref("SVGElement.viewportElement")}}{{readonlyInline}}</dt>
 <dd>The {{domxref("SVGElement")}}, which established the current viewport. Often, the nearest ancestor {{SVGElement("svg")}} element. <code>null</code> if the given element is the outermost <code>&lt;svg&gt;</code> element.</dd>
</dl>

<h2 id="方法">方法</h2>

<p><em><code>SVGElement</code>类本身没有方法, 但拥有从父类{{domxref("Element")}}继承的方法.</em></p>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName("SVG2", "types.html#InterfaceSVGElement", "SVGElement")}}</td>
   <td>{{Spec2("SVG2")}}</td>
   <td>Adds the {{domxref("SVGElement.dataset", "dataset")}} property.</td>
  </tr>
  <tr>
   <td>{{SpecName("SVG1.1", "types.html#InterfaceSVGElement", "SVGElement")}}</td>
   <td>{{Spec2("SVG1.1")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{ CompatibilityTable }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Microsoft Edge</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}<sup>[1]</sup></td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatIE("9.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>dataset</code> attribute</td>
   <td>{{CompatChrome("54")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("51")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOpera("41")}}</td>
   <td>{{CompatSafari("10.0")}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Edge</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}<sup>[1]</sup></td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}} [1]</td>
  </tr>
  <tr>
   <td><code>dataset</code> attribute</td>
   <td>{{CompatNo}}</td>
   <td>54</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile(51)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>41</td>
   <td>10.0</td>
   <td>54</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] 属性 <code>offsetParent</code>, <code>offsetTop</code>, <code>offsetLeft</code>, <code>offsetWidth</code>, 和 <code>offsetHeight</code> 从Chrome 48开始被废弃.</p>

<h2 id="相关链接">相关链接</h2>

<ul>
 <li>HTML {{htmlattrxref("data-*")}} 属性</li>
 <li>SVG {{SVGAttr("data-*")}} 属性</li>
 <li><a href="/zh-CN/docs/Web/Guide/HTML/Using_data_attributes">使用数据属性</a></li>
</ul>