I'm trying to reproduce the behaviour of this SVG explained at this post, but putting the JavaScript in the HTML page, and using D3.js. I try this:
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.js"></script>
<script>
var svg = d3.select("body").append("svg")
.attr("width", 300)
.attr("height", 300)
.attr("id","svgBox");
var svgRect = svg.append("rect")
.attr("width", 200)
.attr("height", 200)
.attr("x", 50)
.attr("y", 50)
.attr("id","rect1")
.style("fill", "#AAFFAA")
.style("stroke", "#222222");
var root = document.getElementById("svgBox");
var rpos = root.createSVGRect();
rpos.x = 150;
rpos.y = 150;
rpos.width = rpos.height = 1;
var list = root.getIntersectionList(rpos, null);
console.info(list);
</script>
But it doesn't work. When trying it in Firefox, the error is
TypeError: root.getIntersectionList is not a function
And in Chrome, there is no error, but the function doesn't seem to work, since the result in list is always empty.
Is there a way to call the function or I should detect if the point is inside the path by using another method?