How do I decrease the "counter" variable in this case?
<p>Let's say I have this function "Person" which can take name or age.</p>

<pre><code>function Person(name, age){
    this.name = name;
    this.age = age;
    this.counter = 0;
};
</code></pre>

<p>A "database" to make new Person objects:</p>

<pre><code>var database = {};
database['tom'] = new Person("Tom", 15);
database['josh'] = new Person("Josh, 20);
</code></pre>

<p>A function to "print" the people to the console:</p>

<pre><code>function printPerson(p, name){
      for (var p in database[name]){
         document.getElementById('output').innerHTML +=('&lt;b&gt;' + p.charAt(0).toUpperCase() + p.slice(1) + '&lt;/b&gt;: ' + database[name][p] + '&lt;br /&gt;');
      }
};
</code></pre>

<p>The following Jquery which takes user input, runs the printPerson function by passing the input as a parameter, and adds it to a div with id output.</p>

<pre><code>$(document).ready(function() {
 $('#button').click(function(){
    var userInput = $('input[name=searchItem]').val();
    userInput = userInput.toLowerCase();
     $('#output').append(printPerson(userInput, userInput));
 });
</code></pre>

<p>And then the following Jquery which incremenets a counter for each person I add to the output div. Then it stores this input in an array called store and appends it to a div called  save</p>

<pre><code>var input = [];
$('#add').click(function(){
     var input = $('input[name=searchItem]').val();
     input = input.toLowerCase();
     database[input].counter++;
      store.push(input);
      $('#save').append('&lt;div id="list"&gt;' + database[store[store.length-1]].name + '&lt;/div&gt;');
 });
</code></pre>

<p>Now.. suppose that I have jquery which removes each name from the div with id list when clicked on like so:</p>

<pre><code>$(document).on('click','[id^=list]', function(){
   $(this).remove();
  });
</code></pre>

<p>At this point, how can I -decrease- the counter for the item that was removed?
database[input].counter-- wont work since there is no "input" in this jquery function. </p>

<p>I'm not even sure if this is possible... are there any recommendations?</p>

<p>To re-iterate, what I'm trying to do is get the user's input, increase a counter for each time the user enters a name that's in my database, and remove that counter each time the user clicks on a div with the stored input.</p>

<p>Example:
User enters Tom, Josh, Tom, Tom. database[tom].counter = 3, and database[josh].counter = 1. If the user clicks on one of the "toms" in the save div, database[tom].counter will decrease back to 2.</p>

<p>Sorry if this is confusing, I tried to explain it as best I can. This isn't my full code or even my actual code but an adaptation/example I made to try to clarify because it would be more confusing if I provided my whole program.</p>

<p>I hope someone can understand what I'm trying to do and offer any insight. Thanks for reading...</p>
