[jQuery] :last, td:eq(0), find(), href
# [jQuery] :last, td:eq(0), find(), href
1. filter(":last")
- 동일 클래스(trIds)에서 마지막 tr 찾기.
- $(".trIds").filter(":last").attr("id").replace("trId", "")
2. find("td:eq(0)")
- 0(1번째) td
- $("#trId1").find("td:eq(0)").find("input").val("ID 추가");
3. href 값 변경
- $("#trId1").find("td:eq(0)").find("a").attr("href", "javascript:addTrId("+nNum+")");
------------------------------------------------------------------------------------------
...
var lastItemNo = parseInt( $(".trIds").filter(":last").attr("id").replace("trId", "") );
var nNum = lastItemNo+1;
...
$("#trId1").attr("id", "addFileNo" + nNum);
$("#trId1").find("td:eq(0)").find("input").attr("id", "trNoInput"+nNum);
$("#trId1").find("td:eq(0)").find("input").val("ID 추가");
$("#trId1").find("td:eq(0)").find("a").attr("href", "javascript:addTrId("+nNum+")");
$("#trId1").find("td:eq(0)").find("span").attr("id", "rtImg"+nNum);
...
------------------------------------------------------------------------------------------
...
<tr id="trId1" class="trIds">
<th>ID</th>
<td>
<input type="text" id="trNoInput1" value="" style="width:353px;" readonly="true">
<a href="javascript:addTrId(1)"><img src="/btn/bt_addId.gif" alt="ID추가"></a>
<span id="rtImg1"></span>
</td>
</tr>
<tr id="trId2" class="trIds">
<th>ID</th>
<td>
<input type="text" id="trNoInput2" value="" style="width:353px;" readonly="true">
<a href="javascript:addTrId(2)"><img src="/btn/
bt_addId .gif" alt="ID추가"></a>
<span id="rtImg1"></span>
</td>
</tr>
<tr id="trId3" class="trIds">
<th>ID</th>
<td>
<input type="text" id="trNoInput3" value="" style="width:353px;" readonly="true">
<a href="javascript:addTrId(3)"><img src="/btn/
bt_addId .gif" alt="ID추가"></a>
<span id="rtImg1"></span>
</td>
</tr>
...
------------------------------------------------------------------------------------------
댓글