Binding jQuery click events via looping through hash grabs last element in hash?
<p>I have a number of divs I am toggling on and off. I initially was manually binding the handlers(as per the code below), but decided to do some refactoring. However, a binding issue arose where the last key/value in the hash is the one always selected. In the example code, that would be the contact_data div. I think the problem is that the data is not being closed over, but I am not certain how to force this in JS.</p>

<pre><code>var link_div = {
    "#about_toggle" : "#about_stuff",
    //more pairs
    "#contact_toggle" : "#contact_data"

 };
/*
 * Before refactoring:
  $("#about_toggle").click( function()
                          {
                              $("#about_stuff").toggle();
                          });
*/
//After
    for(var key in link_div)
    {
        $(key).click(function()
             {
                 alert(link_div[key]);
                 toggle_on_element(link_div[key]);
             });
    }
</code></pre>
