🏠 back to Observable

How to implement color for enter state

Hi! I’m new to D3 and Observable and I’m trying to work through this tutorial:

I’m stuck on the first exercise because I’m unable to add color to items in the enter state (working with selections). I’ve tried enter => enter.append(‘li’).style(‘color’, ‘green’), and enter => enter.append(‘li’).attr(‘color’, ‘green’),
but neither change the color of any entering items.

enter => enter.append('li').style("color", "green") seems right to me! Did you move the slider to add more items after changing the code? It may be a little confusing because the list is being rendered by one cell, and then selected and re-rendered by the one below, which the tutorial asks you to edit. enter will only be called for elements of the newly bound data (here newData) that don’t already have corresponding items (here <li>s) in the selection. Here’s a screen recording.

Ah! Thank you so much! I misunderstood how the sliders worked, your explanation is really helpful

1 Like