I am trying to achieve a hard stop in linear gradient as
CodePudding user response:
const stop2 = document.createElementNS('svgns', 'stop');
should be
const stop2 = document.createElementNS(svgns, 'stop');
See demo: https://codepen.io/smpao1/pen/vYdaWMW
The namespace is set to the namespace 'svgns', which will not get interpreted as a valid svg element, and is thus ignored.