SVGSVGElement

SVG Svg DOM interface

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.

Interface overview

Also implement SVGElement, SVGTests, SVGLangSpace, SVGExternalResourcesRequired, SVGStylable, SVGLocatable, SVGFitToViewBox, SVGZoomAndPan, DocumentEvent, ViewCSS, DocumentCSS
Methods
Properties
Normative document SVG 1.1 (2nd Edition)

Properties

Name Type Description
x SVGAnimatedLength Corresponds to attribute x on the given <svg> element.
y SVGAnimatedLength Corresponds to attribute y on the given <svg> element.
width SVGAnimatedLength Corresponds to attribute width on the given <svg> element.
height SVGAnimatedLength Corresponds to attribute height on the given <svg> element.
contentScriptType DOMString Corresponds to attribute contentScriptType on the given <svg> element.
contentStyleType DOMString Corresponds to attribute contentStyleType on the given <svg> element.
viewport SVGRect The position and size of the viewport (implicit or explicit) that corresponds to this <svg> element. When the browser is actually rendering the content, then the position and size values represent the actual values when rendering. The position and size values are unitless values in the coordinate system of the parent element. If no parent element exists (i.e., <svg> element represents the root of the document tree), if this SVG document is embedded as part of another document (e.g., via the HTML <object> element), then the position and size are unitless values in the coordinate system of the parent document. (If the parent uses CSS or XSL layout, then unitless values represent pixel units for the current CSS or XSL viewport.)
pixelUnitToMillimeterX  float Size of a pixel units (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.
pixelUnitToMillimeterY  float Corresponding size of a pixel unit along the y-axis of the viewport.
screenPixelToMillimeterX  float 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 attribute will express that information; otherwise, user agents will provide a suitable default value such as .28mm.
screenPixelToMillimeterY  float Corresponding size of a screen pixel along the y-axis of the viewport.
useCurrentView boolean 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 as viewBox) or to 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 is false. If the initial view is a "custom" view, then this attribute is true.
currentView SVGViewSpec The definition of the initial view (i.e., before magnification and panning) of the current innermost SVG document fragment. The meaning depends on the situation:
currentTranslate SVGPoint On an outermost <svg> element, the corresponding translation factor that takes into account user "magnification".
currentScale float On an outermost <svg> element, this attribute indicates the current scale factor relative to the initial view to take into account user magnification and panning operations. DOM attributes currentScale and currentTranslate are equivalent to the 2x3 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).

Methods

Name & Arguments Return Description
suspendRedraw(in unsigned long maxWaitMilliseconds) unsigned long

Takes a time-out value which indicates that redraw shall not occur until:

  1. the corresponding unsuspendRedraw() call has been made,
  2. an unsuspendRedrawAll() call has been made, or
  3. 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() and unsuspendRedraw() 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:

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 other suspendRedraw method calls.

unsuspendRedraw(in unsigned long suspendHandleID) void Cancels a specified suspendRedraw() by providing a unique suspend handle ID that was returned by a previous suspendRedraw() call.
unsuspendRedrawAll() void 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 pending suspendRedraw() method calls have been cancelled.
forceRedraw() void In rendering environments supporting interactivity, forces the user agent to immediately redraw all regions of the viewport that require updating.
pauseAnimations() void 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.
unpauseAnimations() void 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.
animationsPaused() boolean Returns true if this SVG document fragment is in a paused state.
getCurrentTime() float 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's SVGLoad event is dispatched), then 0 is returned.
setCurrentTime(in float seconds) void 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's SVGLoad event 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.
getIntersectionList(in SVGRect rect, in SVGElement referenceElement) NodeList Returns the list of 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 in pointer-events processing.
getEnclosureList(in SVGRect rect, in SVGElement referenceElement) NodeList Returns the list of 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 in pointer-events processing.
checkIntersection(in SVGElement element, in SVGRect rect) boolean Returns true if 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 in pointer-events processing.
checkEnclosure(in SVGElement element, in SVGRect rect) boolean Returns true if 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 in pointer-events processing.
deselectAll() void Unselects any selected objects, including any selections of text strings and type-in bars.
createSVGNumber() SVGNumber Creates an SVGNumber object outside of any document trees. The object is initialized to a value of zero.
createSVGLength() SVGLength Creates an SVGLength object outside of any document trees. The object is initialized to a value of zero user units.
createSVGAngle() SVGAngle Creates an SVGAngle object outside of any document trees. The object is initialized to a value of zero degrees (unitless).
createSVGPoint() SVGPoint Creates an SVGPoint object outside of any document trees. The object is initialized to the point (0,0) in the user coordinate system.
createSVGMatrix() SVGMatrix Creates an SVGMatrix object outside of any document trees. The object is initialized to the identity matrix.
createSVGRect() SVGRect Creates an SVGRect object outside of any document trees. The object is initialized such that all values are set to 0 user units.
createSVGTransform() SVGTransform Creates an SVGTransform object outside of any document trees. The object is initialized to an identity matrix transform (SVG_TRANSFORM_MATRIX).
createSVGTransformFromMatrix(in SVGMatrix matrix) SVGTransform Creates an SVGTransform object 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 as SVGTransform::matrix.
getElementById(in DOMString elementId) Element Searches this SVG document fragment (i.e., the search is restricted to a subset of the document tree) for an Element whose id is given by elementId. If an Element is found, that Element is returned. If no such element exists, returns null. Behavior is not defined if more than one element has this id.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) (Yes) 9.0 (Yes) (Yes)
getElementById() ? 11 (11) ? (Yes) ?
useCurrentView ? 15 (15) ? (Yes) ?
contentStyleType and contentStyleScript (Removed from SVG2) ? (Yes)
Removed in 20 (20)
? ? ?
pixelUnitToMillimeterX, pixelUnitToMillimeterY, screenPixelToMillimeterX, and screenPixelToMillimeterY Not supported [1]        
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support Not supported ? (Yes) ? (Yes) (Yes) ?
getElementById() ? ? 11.0 (11) ? ? ? ?
useCurrentView ? ? 15.0 (15) ? ? ? ?
contentStyleType and contentStyleScript (Removed from SVG2) ? Not supported [1] (Yes)
Removed in 20.0 (20)
? ? ? Not supported [1]

[1] Removed in Chrome 47. 

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/svgsvgelement

API NeedsBrowserCompatibility NeedsExample Reference Référence SVG SVG DOM