Q:

Changing attribute of a DOM element using D3 data that is bound to it

I have a D3.js visualization of a DAG, using the force-directed layout.  Sometimes I want to change the colours of certain nodes.  So far, I have done this in click listeners by using this:
function clickNode(node) {
    d3.select(this).attr("fill", nodeHighlightColour);
}

However, now I want to change node colour in a function that is called by a listener, instead of the listener itself.  The reason it has to be a separate function is that I want to "highlight" a series of nodes, tracing back from the node that's clicked, so I need to call the function (tracePath) recursively.
If I call tracePath from the listener, I get an "undefined function" runtime error when I try d3.select(this).attr("fill").  I'm guessing this is because this is no longer in the scope.  I can pass the node object to tracePath, but this is the node data rather than the DOM element.  How do I get the DOM element using just the data object that is bound to it?
EDIT:
As I wrote in my comment to Felix Kling, I can't simply pass this to tracePath.  This will work for the first node, but I still have to call the function recursively.  Here is my tracePath function so far:
// Trace the back from a node - node_el is "this", node is the node data
function tracePath(node_el, node) {
    var this_id = node.id;

    if (node.logic == null) {
            console.log("Highlighting!");
            // Using "this" to change colour
            d3.select(node_el).attr("fill", nodeHighlightColour);
    }
    // Look for edges that point to this node
    for (var i=0; i<edges.length; i++) {
            var e = edges[i];
            if (e.target == this_id) {
                    var next_node = None;

                    // Get the node at the source of the edge
                    for (var j = 0; j<nodes.length; j++) {
                        if (nodes[j].id == e.source) {
                            next_node = nodes[j];
                        }
                    }
                    // Recursively trace back from that node
                    if (next_id != None) {
                            // How do I get the DOM element to pass to tracepath?
                            tracePath(???, next_node);
                    }
            }
    }
}

A:

Thanks Felix Kling for the answer to this!  As he suggested, I added an id to each SVG circle element that was the same as the node data id, like this:
 circle = d3.select('#graphics').append("g").selectAll("circle")
         .data(force.nodes())
         .enter().append("svg:circle")
         .attr("id", function(d) {
              return d.id;
         })
         .on("click", clickNode)

Then, I could access the DOM element using the node id.  Here is my finished tracePath function:
// Trace the path back from a node
function tracePath(node_el, node) {
    var this_id = node.id;
    console.log("in tracepath");
    if (node.logic == null) {
            console.log("Highlighting!");
            d3.select(node_el).attr("fill", nodeHighlightColour);
    }
    console.log("this_id:", this_id);
    // Look for edges that point to this node
    for (var i=0; i<edges.length; i++) {
            var e = edges[i];
            if (e.target.id == this_id) {
                    console.log("edge from ", e.source.name);

                    // Recursively trace back from that node
                    var next_el = document.getElementById(e.source.id);
                    tracePath(next_el, e.source);
            }
    }
}

I also noticed that e.target (where e is an edge) gives me the target node itself, not just the id, so I didn't need to search through the nodes.

