I am trying to figure out why this code of is not working in Firefox. It's supposed to create horizontal paths, but I cannot see them in Firefox. Chrome and IE showing them properly. What could be the issue?
https://jsfiddle.net/7a6qm371/
<div>
<svg width="100%" height="500" id="svgBottomWall">
<g style="stroke: aqua; fill: none;" id="svgBottomWallGridGroup"></g>
</svg>
$(document).ready(function () {
var svgBottomWall = document.getElementById("svgBottomWall");
var rect = svgBottomWall.getBoundingClientRect();
var svgW = rect.width;
function createHorizontalLine(w, d) {
var nline = document.createElementNS("http://www.w3.org/2000/svg", "path");
nline.setAttribute("d", "M 0 " + d + ", L " + w + " " + d);
nline.setAttribute("stroke-width", 1);
nline.setAttribute("stroke", "#ffffff");
document.getElementById("svgBottomWallGridGroup").appendChild(nline);
}
for (var i = 0; i <= svgW; i = i + 100) {
createHorizontalLine(svgW, i);
}
});
Your d
path parameters are incorrectly formatted.
You have something like
d="M 0 100, L 1000 100"
whereas it should be
d="M 0,100 L 1000,100"
See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
The fix is
nline.setAttribute("d", "M 0," + d + " L " + w + "," + d);
JSFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With