Is an event handler bound to an element, so you can trigger the event with different selectors? Look the example below to see what I want to know:
Example:
HTML
<ul id="itemsList">
<li class="items" id="item1">element1</li>
<li class="items" id="item2">element2</li>
<li class="items" id="item3">element3</li>
</ul>
Javascript in which click event handler is defined:
$('.items').click(function(){
//do something
});
To invoque this handler I think it’s possible to do in several ways, using different selectors, therefore $('#item1').click(); and $(#itemsList li).eq(1).click(); would call the same event handler. Right?
If yes I’m certainly doing something wrong because it’s not working properly…
I have a few things to point out:
"in the expression$(#itemsList li).eq(1).click();.eq(1)actually selects secondli, because eq index starts at 0.Correct syntax:
jsFiddle demo