// Get an SVGLength object
const svg = document.querySelector("svg");
// Assume `length` is an instance of SVGLength
const length = svg.createSVGLength();
// Set the length value
length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PERCENTAGE, 20);
// Check the unit type
console.log(length.unitType); // Output: 2 (SVG_LENGTHTYPE_PERCENTAGE)SVGLength: unitType property / notebook
SVGLength: unitType property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.