jquery - Catch event on nth div click -


what's possible way catch event on click, if event target must nth div? example, we've following html:

<div id="wrapper">    <div class="item"></div>    <div class="item"></div>    <div class="item"></div> </div> 

how can fire event if have clicked on second div?

something that:

if($(event.target).is('item:eq(1)')){alert('second')}    

or

if($(event.target).is('.item:eq(1)')){alert('second')}   

is not working. jsfiddle quick edit: http://jsfiddle.net/uxqm2/

thanks answers. don't need code strictly binded on 1 element, that's why asking event target. i've function starting

clicktarget.on('click', function(event){ //some code here }); 

where clicktarget item class example above. , don't want write 3 functions work similar change 1 line of code - it's not good, asked because want catch event inside function , change 1 line of code. guess index() should trick.

class doesn't matter. jquery takes current element on click defaultly using $(this) - denotes current element

$('.item').on('click', function(event){         alert($(this).index() + 1)      }); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -