title: d3.js Alternate colors on click and change back to original on click of another dot
body: <p>I am working with a scatterplot in d3 and each dot on the graph represents a paper. </p>
  
  <p>All dots are blue on the graph but on click I want that selected paper to change color eg (yellow). But when another dot is clicked I want that first dot to go back to blue and the newly selected dot to turn yellow. How would I achieve this? I have a function called clickHandler which is called when the circles are created at the on click attribute. </p>
  
  <p>Here is a similar question <a href="https://stackoverflow.com/questions/10939082/d3-javascript-alternate-colors-on-click">d3 javascript alternate colors on click</a></p>
  
  <p>But instead of the circle turning back to the original color on the second click of that circle I want it to turn back on a click of another circle. </p>
  
  <p>The following code is from the question linked above, I was wondering would I be on the right track thinking this is the method I should be following for what I want?:</p>
  
  <pre><code>function clickHandler (d, i) {
  
  var toggleColor = (function() {
  
          var currentColor = "blue";
              return function() {
                  currentColor = currentColor == "blue" ? "yellow" : "blue";
                  d3.select(this).style("fill", currentColor)
                                  .style("stroke", "black");
              }
      })
  }
  </code></pre>
  
  <p>Any help is greatly appreciated! Thanks in advance!</p>