files/en-us/web/api/svglength/newvaluespecifiedunits/index.md
{{APIRef("SVG")}}
The newValueSpecifiedUnits() method of the {{domxref("SVGLength")}} interface resets the value as a number with an associated {{domxref("SVGLength.unitType", "unitType")}}, thereby replacing the values for all of the attributes on the object.
newValueSpecifiedUnits(unitType, valueInSpecifiedUnits)
unitType
SVG_LENGTHTYPE_UNKNOWN.
SVGLength.SVG_LENGTHTYPE_NUMBER: convert to unitless numberSVGLength.SVG_LENGTHTYPE_PERCENTAGE: convert to percentageSVGLength.SVG_LENGTHTYPE_EMS: convert to em unitsSVGLength.SVG_LENGTHTYPE_EXS: convert to ex unitsSVGLength.SVG_LENGTHTYPE_PX: convert to pixelsSVGLength.SVG_LENGTHTYPE_CM: convert to centimetersSVGLength.SVG_LENGTHTYPE_MM: convert to millimetersSVGLength.SVG_LENGTHTYPE_IN: convert to inchesSVGLength.SVG_LENGTHTYPE_PT: convert to pointsSVGLength.SVG_LENGTHTYPE_PC: convert to picasvalueInSpecifiedUnits
None ({{jsxref('undefined')}}).
This method may raise a {{domxref("DOMException")}} of one of the following types:
NotSupportedError {{domxref("DOMException")}}
unitType is SVG_LENGTHTYPE_UNKNOWN or not a valid unit type constant.NoModificationAllowedError {{domxref("DOMException")}}
// Get an SVGLength object
const svg = document.querySelector("svg");
const length = svg.createSVGLength();
// Set a new value with specific units
length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER, 45);
console.log(length.valueInSpecifiedUnits); // Output: 45
console.log(length.unitType); // Output: 1 (SVG_LENGTHTYPE_NUMBER)
console.log(length.value); // The value converted to the user coordinate system
// Change the value to pixels
length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 100);
console.log(length.valueInSpecifiedUnits); // Output: 100
console.log(length.unitType); // Output: 5 (SVG_LENGTHTYPE_PX)
{{Specifications}}
{{Compat}}