Using d3.js I want to insert attributes of a specific namespace into SVG elements (embedded in a HTML5 document), more precisely that.
So I have the following JavaScript:
d3.select("body")
.append("svg")
.attr({width: 100, height: 100})
.append("rect")
.attr({width: 100, height: 100})
.attr("myns:foo", "bar");
CSS:
rect[foo] {
fill: red;
}
rect[myns\:foo] {
fill: green;
}
Results in:
<html>
<head>…</head>
<body>
<svg width="100" height="100">
<rect width="100" height="100" foo="bar"></rect>
</svg>
</body>
</html>
see JSFiddle
I expected the generated rectangle to be green, but instead it is red. Also I wonder why the attribute is not myns:foo
.
I also experimented with d3.ns.prefix
(until I read that) and the CSS3 @namespace
, however without success.
So can you explain to me why the code above does not work as intended and could you provide an alternative?