score:1

Accepted answer

Give an ID to your text in the render function:

this.body.append("svg:text")
    .attr("id", "textLabel")
    //etc...

And select by class in the redraw function:

this.body.select("#textLabel")
    .text(value)

If that is the only <text> element in the SVG selection, you could simply do...

this.body.select("text")
    .text(value)

... without any ID or class.

A third solution is naming a selection outside both function, which you could change inside them.

Finally, two advices:

First, you said "I am using a combination of jQuery & d3.js". That's almost always a terrible idea. Don't do that.

Second, I'd advise you to mind the names of your variables and objects. You are referring to a SVG selection as body. Normally, we would expect that this.body refers to the <body>. Thus, change it to this.svg, it's clearer for whoever is reading your code.


Related Query

More Query from same tag