我有一些這樣的。如何構建jQuery刪除
<script src="http://code.jquery.com/jquery-latest.js"></script>
<table>
<tr title="test" id="ex1">
<td><div class="move">Hello</div></td>
<td> </td>
<td> </td>
</tr>
<tr id="ex2">
<td><div class="move">Hello</div></td>
<td> </td>
<td> </td>
</tr>
</table>
<button>Move</button>
<script>
$("button").click(function() {
$(".move").remove();
});
</script>
如果我按下按鈕,兩個div都會移動。但是我只需要移動一個,根據它放置的標識。
我只有錯誤的想法:
$(".move").parent.parent.attr('id', 'ex2').remove();
太謝謝你了!
我覺得這其實是最好的答案,如果只有EX2是一個類,而不是一個ID?它應該是$(「#ex2 .move」)。remove(); – adeneo
它應該不是'$('#ex2 .move「)。remove()'作爲'ex2'是一個ID? –
是的,我的不好,是固定的。 –