[jQuery] reverse, each 거꾸로 읽어서 삭제
# [jQuery] reverse, each 거꾸로 읽어서 삭제.
1. reverse
- 테이블의 tr을 뒤에서 읽어면서 삭제 처리함.
2. each
- tr 수만큼 반복.
3. remove
- 첫번째 tr은 삭제하지 않음.
------------------------------------------------------------------------------------------
$($("#tesTable tr").get().reverse()).each( function() {
var num = $(this).attr("id").replace("tr", "");
if(num>1) {
$(this).attr("id", "tr" + num).remove();
}
});
------------------------------------------------------------------------------------------
<table id="tesTable" border="0" cellpadding="0" cellspacing="0" width="126">
<colgroup><col width="30"><col width="96"></colgroup>
<tr id="tr1" >
<td 1</td>
<td><input style="ime-mode:disabled" type="text" ></td>
</tr>
<tr id="tr2" >
<td>2</td>
<td><input style="ime-mode:disabled" type="text" ></td>
</tr>
<tr id="tr3" >
<td>3</td>
<td><input style="ime-mode:disabled" type="text" ></td>
</tr>
</table>
------------------------------------------------------------------------------------------
댓글