Reputation: 4007
I am trying to make a bunch of 0/1 svg text elements in a row which once clicked, flips.
I followed d3js update pattern, with update()
on-click. It didn't work
shown here (live code on tributary).
Then I changed from this line
t1.enter().append("text").attr("y",205).attr("x",function(d,i) {return(40+i*80-4)}).text(function(d){return d})
.attr("fill", "red");
to that
t1.enter().append("text").attr("y",205).attr("x",function(d,i){return(40+i*80-4)});
t1.text(function(d){return d}).attr("fill", "red");
Now it worked shown here (live code on tributary).
In other words, I broke the "chained" calls at .text(function ...)
But why, shouldn't they all return the same object in the chain?
Upvotes: 0
Views: 34
Reputation: 108537
In the first code snippet, you are setting the text on the enter
selection. On each additional update()
call, nothing enters the selection, therefore the text does not update.
In the second code snippet, you are correctly setting the text on the larger update
selection.
Note, t1
is the update selection. t1.enter()
is the enter selection.
Upvotes: 1