SVGElement: viewportElement property

Baseline Widely available

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

The viewportElement property of the SVGElement interface represents the SVGElement which established the current viewport. Often the nearest ancestor element. null if the given element is the outermost element.

Value

Examples

Retrieving the viewportElement

html

  
    
  

js
const circle = document.getElementById("circle");
const innerSvg = document.getElementById("innerSvg");
const outerSvg = document.getElementById("outerSvg");

console.log(circle.viewportElement); // Output: ...
console.log(innerSvg.viewportElement); // Output: ...
console.log(outerSvg.viewportElement); // Output: null

Specifications

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGElement__viewportElement

Browser compatibility

See also