i want do build a small “listbox” selection in jquery.
<div id="first">
<ul>
<li><a href="#">abc</a></li>
<li><a href="#" class="active">abc1</a></li>
<li><a href="#">abc2</a></li>
</ul>
i wanted to create first a function, if i click on the href, the class ‘active’ shoud be add, if its already added, i wanted to remove this.
$('#first').click( function(e)
{
$('a[href=#]').click( function(e)
{
alert('bla');
})
})
but he is doing the alert 3 times :-/
look at jsfiddle
If your idea is to add or remove the class active to the corresponding anchor tag i dont think you need to have a click function on on the div that contains the list.. all u need to do is