文章加密

;

2017年11月28日 星期二

Get index of clicked element, and use on another element

I just use

$('selector').click(function (index) {
   $('another').eq(i) //do something
});
but not working.

And this way it works
$('selector').click(function(){
    var a = $('selector').index(this) );
    $('another').eq(a)  //do something
});


Extend learning

select all element except the clicked one
$('selector').click(function(){
    var a = $('selector').index(this) );
    $('another').not(this)   //do something
    $('another').eq(a)  //do something
});
it is important that .not() writing at the above.


沒有留言:

張貼留言