You are appending new elements instead of updating the existing ones. The line


takes care of this and should be deleted if you want to update the existing data. Calling .enter() after .data() will give you the data that previously wasn't there, .exit() the data that is not there anymore. If you find that the old and the new data aren't merged correctly, you can use the optional second argument to .data() to supply a merge function.

Related Query