SVGSVGElement
The SVGSVGElement interface provides access to the properties of <svg> elements, as well as methods to manipulate them. This interface contains also various miscellaneous commonly-used utility methods, such as matrix operations and the ability to control the time of redraw on visual rendering devices.
Properties
This interface also inherits properties from its parent, SVGGraphicsElement and also implements the ones from SVGFitToViewBox and WindowEventHandlers.
-
SVGSVGElement.xRead only -
An
SVGAnimatedLengthcorresponding to thexattribute of the given<svg>element. -
SVGSVGElement.yRead only -
An
SVGAnimatedLengthcorresponding to theyattribute of the given<svg>element. -
SVGSVGElement.widthRead only -
An
SVGAnimatedLengthcorresponding to thewidthattribute of the given<svg>element. -
SVGSVGElement.heightRead only -
An
SVGAnimatedLengthcorresponding to theheightattribute of the given<svg>element. SVGSVGElement.contentScriptType-
An
SVGAnimatedLengthcorresponding to thecontentScriptTypeattribute of the given<svg>element. SVGSVGElement.contentStyleType-
An
SVGAnimatedLengthcorresponding to thecontentStyleTypeattribute of the given<svg>element. -
SVGSVGElement.pixelUnitToMillimeterX -
A float representing the size of the pixel unit (as defined by CSS2) along the x-axis of the viewport, which represents a unit somewhere in the range of 70dpi to 120dpi, and, on systems that support this, might actually match the characteristics of the target medium. On systems where it is impossible to know the size of a pixel, a suitable default pixel size is provided.
-
SVGSVGElement.pixelUnitToMillimeterY -
A float representing the size of a pixel unit along the y-axis of the viewport.
-
SVGSVGElement.screenPixelToMillimeterX -
User interface (UI) events in DOM Level 2 indicate the screen positions at which the given UI event occurred. When the browser actually knows the physical size of a "screen unit", this float attribute will express that information; otherwise, user agents will provide a suitable default value (such as
.28mm). -
SVGSVGElement.screenPixelToMillimeterY -
Corresponding size of a screen pixel along the y-axis of the viewport.
SVGSVGElement.useCurrentView-
The initial view (i.e., before magnification and panning) of the current innermost SVG document fragment can be either the "standard" view, i.e., based on attributes on the
<svg>element such asviewBox) or on a "custom" view (i.e., a hyperlink into a particular<view>or other element). If the initial view is the "standard" view, then this attribute isfalse. If the initial view is a "custom" view, then this attribute istrue. SVGSVGElement.currentView-
An
SVGViewSpecdefining the initial view (i.e., before magnification and panning) of the current innermost SVG document fragment. The meaning depends on the situation: If the initial view was a "standard" view, then:- the values for
viewBox,preserveAspectRatioandzoomAndPanwithincurrentViewwill match the values for the corresponding DOM attributes that are onSVGSVGElementdirectly - the values for
transformandviewTargetwithincurrentViewwill benull
If the initial view was a link into a
<view>element, then:- the values for
viewBox,preserveAspectRatioandzoomAndPanwithincurrentViewwill correspond to the corresponding attributes for the given<view>element - the values for
transformandviewTargetwithincurrentViewwill benull
If the initial view was a link into another element (i.e., other than a
<view>), then:- the values for
viewBox,preserveAspectRatioandzoomAndPanwithincurrentViewwill match the values for the corresponding DOM attributes that are onSVGSVGElementdirectly for the closest ancestor<svg>element - the values for
transformwithincurrentViewwill benull - the
viewTargetwithincurrentViewwill represent the target of the link
If the initial view was a link into the SVG document fragment using an SVG view specification fragment identifier (i.e.,
#svgView(…)), then:- the values for
viewBox,preserveAspectRatio,zoomAndPan,transformandviewTargetwithincurrentViewwill correspond to the values from the SVG view specification fragment identifier
- the values for
SVGSVGElement.currentScale-
On an outermost
<svg>element, this float attribute indicates the current scale factor relative to the initial view to take into account user magnification and panning operations. DOM attributescurrentScaleandcurrentTranslateare equivalent to the 2×3 matrix[a b c d e f] = [currentScale 0 0 currentScale currentTranslate.x currentTranslate.y]. If "magnification" is enabled (i.e.,zoomAndPan="magnify"), then the effect is as if an extra transformation were placed at the outermost level on the SVG document fragment (i.e., outside the outermost<svg>element). -
SVGSVGElement.currentTranslateRead only -
An
SVGPointrepresenting the translation factor that takes into account user "magnification" corresponding to an outermost<svg>element. The behavior is undefined for<svg>elements that are not at the outermost level.
Methods
This interface also inherits methods from its parent, SVGGraphicsElement and also implements the ones from SVGFitToViewBox and WindowEventHandlers.
-
SVGSVGElement.suspendRedraw() -
Takes a time-out value which indicates that redraw shall not occur until:
the corresponding
unsuspendRedraw()call has been made, anunsuspendRedrawAll()call has been made, or its timer has timed out.In environments that do not support interactivity (e.g., print media), then redraw shall not be suspended. Calls to
suspendRedraw()andunsuspendRedraw()should, but need not be, made in balanced pairs.To suspend redraw actions as a collection of SVG DOM changes occur, precede the changes to the SVG DOM with a method call similar to:
const suspendHandleID = suspendRedraw(maxWaitMilliseconds)
and follow the changes with a method call similar to:
unsuspendRedraw(suspendHandleID)
Note that multiple
suspendRedraw()calls can be used at once, and that each such method call is treated independently of the othersuspendRedraw()method calls. -
SVGSVGElement.unsuspendRedraw() -
Cancels a specified
suspendRedraw()by providing a unique suspend handle ID that was returned by a previoussuspendRedraw()call. -
SVGSVGElement.unsuspendRedrawAll() -
Cancels all currently active
suspendRedraw()method calls. This method is most useful at the very end of a set of SVG DOM calls to ensure that all pendingsuspendRedraw()method calls have been cancelled. -
SVGSVGElement.forceRedraw() -
In rendering environments supporting interactivity, forces the user agent to immediately redraw all regions of the viewport that require updating.
SVGSVGElement.pauseAnimations()-
Suspends (i.e., pauses) all currently running animations that are defined within the SVG document fragment corresponding to this
<svg>element, causing the animation clock corresponding to this document fragment to stand still until it is unpaused. SVGSVGElement.unpauseAnimations()-
Unsuspends (i.e., unpauses) currently running animations that are defined within the SVG document fragment, causing the animation clock to continue from the time at which it was suspended.
SVGSVGElement.animationsPaused()-
Returns
trueif this SVG document fragment is in a paused state. SVGSVGElement.getCurrentTime()-
Returns the current time in seconds relative to the start time for the current SVG document fragment. If
getCurrentTime()is called before the document timeline has begun (for example, by script running in a<script>element before the document'sSVGLoadevent is dispatched), then0is returned. SVGSVGElement.setCurrentTime()-
Adjusts the clock for this SVG document fragment, establishing a new current time. If
setCurrentTime()is called before the document timeline has begun (for example, by script running in a<script>element before the document'sSVGLoadevent is dispatched), then the value of seconds in the last invocation of the method gives the time that the document will seek to once the document timeline has begun. SVGSVGElement.getIntersectionList()-
Returns a
NodeListof graphics elements whose rendered content intersects the supplied rectangle. Each candidate graphics element is to be considered a match only if the same graphics element can be a target of pointer events as defined inpointer-eventsprocessing. SVGSVGElement.getEnclosureList()-
Returns a
NodeListof graphics elements whose rendered content is entirely contained within the supplied rectangle. Each candidate graphics element is to be considered a match only if the same graphics element can be a target of pointer events as defined inpointer-eventsprocessing. SVGSVGElement.checkIntersection()-
Returns
trueif the rendered content of the given element intersects the supplied rectangle. Each candidate graphics element is to be considered a match only if the same graphics element can be a target of pointer events as defined inpointer-eventsprocessing. SVGSVGElement.checkEnclosure()-
Returns
trueif the rendered content of the given element is entirely contained within the supplied rectangle. Each candidate graphics element is to be considered a match only if the same graphics element can be a target of pointer events as defined inpointer-eventsprocessing. SVGSVGElement.deselectAll()-
Unselects any selected objects, including any selections of text strings and type-in bars.
SVGSVGElement.createSVGNumber()-
Creates an
SVGNumberobject outside of any document trees. The object is initialized to0. SVGSVGElement.createSVGLength()-
Creates an
SVGLengthobject outside of any document trees. The object is initialized to0user units. SVGSVGElement.createSVGAngle()-
Creates an
SVGAngleobject outside of any document trees. The object is initialized to a value of0degrees (unitless). SVGSVGElement.createSVGPoint()-
Creates an
SVGPointobject outside of any document trees. The object is initialized to the point(0,0)in the user coordinate system. SVGSVGElement.createSVGMatrix()-
Creates an
SVGMatrixobject outside of any document trees. The object is initialized to the identity matrix. SVGSVGElement.createSVGRect()-
Creates an
SVGRectobject outside of any document trees. The object is initialized such that all values are set to0user units. SVGSVGElement.createSVGTransform()-
Creates an
SVGTransformobject outside of any document trees. The object is initialized to an identity matrix transform (SVG_TRANSFORM_MATRIX). SVGSVGElement.createSVGTransformFromMatrix()-
Creates an
SVGTransformobject outside of any document trees. The object is initialized to the given matrix transform (i.e.,SVG_TRANSFORM_MATRIX). The values from the parameter matrix are copied, the matrix parameter is not adopted asSVGTransform::matrix. SVGSVGElement.getElementById()-
Searches this SVG document fragment (i.e., the search is restricted to a subset of the document tree) for an Element whose
idis given byelementId. If an Element is found, that Element is returned. If no such element exists, returnsnull. Behavior is not defined if more than one element has this id.
Specifications
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
SVGSVGElement |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
animationsPaused |
1 |
79 |
1.5 |
No |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
checkEnclosure |
1 |
12 |
1.5-21 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4-21 |
≤12.1 |
1 |
1.0 |
checkIntersection |
1 |
12 |
1.5-21 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4-21 |
≤12.1 |
1 |
1.0 |
contentScriptType |
1-36 |
12-79 |
1.5-20 |
9 |
≤12.1-23 |
3-13.1 |
1-37 |
18-36 |
4-20 |
≤12.1-24 |
1-13.4 |
1.0-3.0 |
contentStyleType |
1-36 |
12-79 |
1.5-20 |
9 |
≤12.1-23 |
3-13.1 |
1-37 |
18-36 |
4-20 |
≤12.1-24 |
1-13.4 |
1.0-3.0 |
createSVGAngle |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
createSVGLength |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
createSVGMatrix |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
createSVGNumber |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
createSVGPoint |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
createSVGRect |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
createSVGTransform |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
createSVGTransformFromMatrix |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
currentScale |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
currentTranslate |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
currentView |
21-56 |
No |
1.5-21 |
No |
15-43 |
7
See bug 226721.
|
≤37-56 |
25-56 |
4-21 |
14-43 |
7
See bug 226721.
|
1.5-6.0 |
deselectAll |
1 |
12 |
25 |
9 |
≤12.1 |
3 |
≤37 |
18 |
25 |
≤12.1 |
1 |
1.0 |
forceRedraw |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
getCurrentTime |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
getElementById |
6 |
12 |
11 |
9 |
≤12.1 |
5.1 |
≤37 |
18 |
Yes |
≤12.1 |
5 |
1.0 |
getEnclosureList |
1 |
12 |
No |
9 |
≤12.1 |
3 |
≤37 |
18 |
No |
≤12.1 |
1 |
1.0 |
getIntersectionList |
1 |
12 |
No |
9 |
≤12.1 |
3 |
≤37 |
18 |
No |
≤12.1 |
1 |
1.0 |
height |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
pauseAnimations |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
pixelUnitToMillimeterX |
1-47 |
12-79 |
1.5-61 |
9 |
≤12.1-34 |
3-13.1 |
≤37-47 |
18-47 |
4-61 |
≤12.1-34 |
1-13.4 |
1.0-5.0 |
pixelUnitToMillimeterY |
1-47 |
12-79 |
1.5-61 |
9 |
≤12.1-34 |
3-13.1 |
≤37-47 |
18-47 |
4-61 |
≤12.1-34 |
1-13.4 |
1.0-5.0 |
preserveAspectRatio |
1 |
12 |
1.5 |
9 |
≤12.1 |
≤4 |
≤37 |
18 |
4 |
≤12.1 |
≤3 |
1.0 |
screenPixelToMillimeterX |
1-47 |
12-79 |
1.5-61 |
9 |
≤12.1-34 |
3-13.1 |
≤37-47 |
18-47 |
4-61 |
≤12.1-34 |
1-13.4 |
1.0-5.0 |
screenPixelToMillimeterY |
1-47 |
12-79 |
1.5-61 |
9 |
≤12.1-34 |
3-13.1 |
≤37-47 |
18-47 |
4-61 |
≤12.1-34 |
1-13.4 |
1.0-5.0 |
setCurrentTime |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
suspendRedraw |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
unpauseAnimations |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
unsuspendRedraw |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
unsuspendRedrawAll |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
useCurrentView |
1-56 |
No |
15
See bug 1174097.
|
No |
≤12.1-43 |
3
See bug 226721.
|
≤37-56 |
18-56 |
15
See bug 1174097.
|
≤12.1-43 |
1
See bug 226721.
|
1.0-6.0 |
viewBox |
1 |
12 |
1.5 |
9 |
≤12.1 |
≤4 |
≤37 |
18 |
4 |
≤12.1 |
≤3 |
1.0 |
width |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
x |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
y |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SVGSVGElement