How can I assign click function to many buttons using JQuery?
<p>I have 29 buttons: todayResultsbutton0 .. todayResultsbutton28,<br>
and 29 divs: todayResultsUrls0 .. todayResultsUrls28.<br>
I also have a function toggleVisibility(divName) that hide/show the given div.
I am trying to use the following code:</p>

<pre><code>for (var i=0;  i &lt; 29; ++i) {
    var b = "#todayResultsbutton"+i;
    var d = "todayResultsUrls"+i;
    $(b).click(function(){toggleVisibility(d);});
}
</code></pre>

<p>I thought that this will cause each button click to show/hide the matching div but the actual result is that clicking on any button (0 .. 28) show/hide the last div - todayResultsUrls28.</p>

<p>Can someone tell me where am I wrong?<br>
Thanks.</p>
