2012-07-31 74 views
0

我有一個類容器中的按鈕列表。jQuery按鈕位置索引

<div class="buttonContainer"> 
    <button id="ONE">ONE</button> 
    <button id="TWO">TWO</button> 
    <button id="THREE">THREE</button> 
</div> 

我想要得到的是,我點擊了按鈕的數字位置:

$('.buttonContainer button').click(function (e) { 
    var id = this.id; 

    // id contains the name of the id of the button clicked. 

}); 

我已經試過: $( 'buttonContainer button.clicked')指數();

但這不起作用。有沒有人有更好的建議?

回答

0

我只是找到了答案:

var index = $(this).index();