What is $ here? I think you need to confirm $("svgroot") would return a DOMElement rather than any other object. As querySelectorAll is natively supported in Selector API, you have an alternative syntax like:
var someids = document.querySelectorAll("#svgroot g[id^='kaart']");
// equivalent to: document.getElementById("svgroot").querySelectAll("g[id^='kaart']")
or just use d3 way:
d3.selectAll("#svgroot g[id^='kaart']")