Binding Events rather than using onclick
<p>I have been told its better to bind events to elements rather than having <code>onclick</code>s with functions everywhere. I agree with this as it devolves more from the HTML which means cleaner and easier to debug code. </p>

<p>But I am having trouble doing this! I loop through some data with PHP (see below) and I currently use onclick to call a function. How can I bind this onclick event to many elements using JQuery.</p>

<pre><code>&lt;?php foreach($main_tags as $key=&gt;$value){ ?&gt;
&lt;li&gt;
    &lt;a id="&lt;?php echo $key; ?&gt;" href="#" onclick="tag_search('&lt;?php echo $key; ?&gt;'); return false;"&gt;
    &lt;?php echo $key; ?&gt;
        &lt;span class="num-active"&gt;
            &lt;?php echo $value; ?&gt;
        &lt;/span&gt;
    &lt;/a&gt;
&lt;/li&gt;
&lt;?php } ?&gt; 
</code></pre>

<p>Thanks all for any help</p>
