Set element attribute conditionally with an if statement

When updating a data join, I would like to set an attribute if a condition is met, otherwise do not update it. A few ways I’ve thought of are:

  1. Set the attribute each update. If the condition is met, set a new value, otherwise, reset the current value.
  2. call a function that sets an attribute if a condition is met
  3. Have two update functions that are selected with an if statement

I don’t know how to make any of these work, could someone help me?

This is my project. If the user updates the HTML form above the graph, I’d like the light blue point to transition from its old position to the new position. But if the user presses enter, I want the light blue point to start at the dark blue point, and then move to its new position