2010-08-14 5 views
3

는 문제가 $j('.innerCellElement').width(this.parentElement.clientWidth - 1);
을 내가 말할 때 this 나는 선택자의 현재 요소를 의미한다. 그러나, 내가 원하는 방식으로 해석되지 않습니다. 여기서 루프를 할 수 있지만이 문제를 해결하는 우아한 방법이 있는지 알고 싶습니다. 당신의 jQuery ≥1.4.1를 사용하는 경우
jQuery를 클래스를 선택하고 '이'참조 여기

답변

2

the .width() method 입력으로 기능을 수행 할 수 있습니다 컬렉션을 통해

$('.innerCellElement').width(function(){ return this.parentElement.clientWidth - 1; }); 

그렇지 않으면 루프.

$('.innerCellElement').each(function(){ 
    $(this).width(this.parentElement.clientWidth - 1); 
});