SVGElement

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

* Some parts of this feature may have varying levels of support.

与 SVG 语言中的元素直接对应的所有 SVG DOM 接口都派生自 SVGElement 接口。

EventTarget Node Element SVGElement

实例属性

也从 Element 接口继承属性。

SVGElement.attributeStyleMap 只读

表示元素的 style 属性声明的 StylePropertyMap

HTMLElement.dataset 只读

提供了命名数据属性的键/值对列表的 DOMStringMap 对象,这些数据属性与附加到元素上的自定义数据属性相对应。这些属性也可以在 SVG 中使用 data-* 形式的属性来定义,其中 * 是数据对的关键名称。这就像 HTML 的 HTMLElement.dataset 属性和 HTML 的 data-* 全局属性一样。

SVGElement.className 已弃用 只读

反映给定元素上 class 属性的 SVGAnimatedString 值;如果不存在 class,则为空字符串。该属性已被弃用,可能会在本规范的未来版本中删除。建议作者使用 Element.classList 代替。

SVGElement.nonce

返回内容安全策略用于确定是否允许进行给定获取请求的密码学数字。

SVGElement.ownerSVGElement 只读

指向最近祖先 <svg> 元素的 SVGSVGElement。如果给定元素是最外层的 <svg> 元素,则为 null

SVGElement.style

表示元素的 style 属性声明的 CSSStyleDeclaration

SVGElement.tabIndex

元素在标签顺序中的位置。

SVGElement.viewportElement 只读

建立当前视口的 SVGElement 元素。通常是最近的祖先 <svg> 元素。如果给定元素是最外层的 <svg> 元素,则为 null

实例方法

此接口本身没有方法,但从 Element 继承方法。

事件

使用 addEventListener() 监听这些事件,或将事件监听器分配给等效的 on... 处理器属性。

abort

当页面在 SVG 元素完全加载之前停止加载时触发。

error

当 SVG 元素无法正常加载或脚本执行过程中发生错误时触发。

load

在浏览器中加载 SVGElement 时触发。

resize

在调整 SVG 文档大小时触发。

scroll

当 SVG 文档视图沿 X 轴和/或 Y 轴移动时触发。

unload

当 DOM 实现从窗口或框架中移除 SVG 文档时触发。

规范

Specification
Scalable Vector Graphics (SVG) 2
# InterfaceSVGElement

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
SVGElement
attributeStyleMap
autofocus
blur
className
Deprecated
dataset
error event
focus
options.preventScroll parameter
load event
nonce
ownerSVGElement
style
tabIndex
viewportElement

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Deprecated. Not for use in new websites.
See implementation notes.
Uses a non-standard name.
Has more compatibility info.

参见