title: jQuery append value on click and replace
body: <p>I'm trying to append the <code>button</code> text to the <code>span</code> but have it only show the value from the last clicked <code>button</code> under each <code>.item</code>. </p>
  
  <p>So whatever the <code>button</code> text is that is clicked, <code>append</code> it to the <code>span</code> and have that value replaced by the next pressed <code>button</code> text, and so on.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(".list").on("click", ".button", function() {
    var x = $(this).closest(".item");
    var y = $(".button").text();
    $('#value').append('(' + y + ')');
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="list"&gt;
    &lt;div class="item"&gt;
      &lt;div&gt;Item 1&lt;/div&gt;
      &lt;button class="button"&gt;50&lt;/button&gt;
    &lt;/div&gt;
    &lt;div class="item"&gt;
      &lt;div&gt;Item 2&lt;/div&gt;
      &lt;button class="button"&gt;30&lt;/button&gt;
    &lt;/div&gt;
    &lt;div class="item"&gt;
      &lt;div&gt;Item 3&lt;/div&gt;
      &lt;button class="button"&gt;70&lt;/button&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;span id="value"&gt;Total:&lt;/span&gt;</code></pre>
  </div>
  </div>
  </p>