2009-12-02 9 views

답변

6

은, 문맥합니다 (this 키워드) 이벤트를 실행 한 DOM 요소를 참조, 당신은 예를 들어,에서 ID를 얻을 수 있습니다 :

$('div[id]').click(function() { // all divs that have an id attribute 
    var id = this.id; // or $(this).attr('id'); 

    someOtherFunction(id); 
}); 
2

을의 맥락에서 click 핸들러 this은 클릭 된 DOM 요소에 해당합니다. 이것을 사용하여 id을 추출 할 수 있습니다.

$('div').click(function() { 
    // Get the id of the clicked div 
    var id = this.id; 
    // Do something with it ... 
}); 
관련 문제