ReorderTable rows with jQuery but exclude the nested tables
I'm trying to exclude nested tables/tr from my Reorder Table script. I have looked at the topic of JQuery and nest tables. Everything I try only work half way. $("#table tr.table_row1") or $("table > tr.order_rows")
it's in a for loop and picks up the order from an array. I would appreciate any help.
Heres' my code:
<table>
<tr class="order_rows"> <- pick this row
<td>
<table>
<tr> <- dont pick this
<td><input type="text" name="order1" value="1" id="order1" size="2" /></td>
<td></td>
</tr>
<tr> <- dont pick this row
<td>...</td>
</tr>
</table>
</td>
</tr>
<tr class="order_rows"> <- pick this row
<td>
<table>
<tr> <- dont pick this row
<td><input type="text" name="order1" value="1" id="order1" size="2" /></td>
</tr>
<tr> <- dont pick this row
<td>...</td>
</tr>
</table>
</td>
</tr>
</table>
This is my JQuery that I'm workin开发者_高级运维g on.
function reorder(NewOrder)
{
var orderedTrs = new Array();
alert(NewOrder);
for ( i=0; i<=NewOrder.length; i++ ) orderedTrs[i] = $("#table tr")[NewOrder[i]];
alert(orderedTrs);
for ( i=0; i<=NewOrder.length; i++ ) $("#table").append(orderedTrs[i]);
}
$(document).ready(function()
{
$(".updateButton:button").click(function()
{
var NewOrder = new Array;
NewOrder[0] = parseInt($("#order1").val());
NewOrder[1] = parseInt($("#order2").val());
reorder(NewOrder);
});
});
I haven't evaluated the logic of the rest of your code, but the most obvious answer to your issue would be to modify your selector from
$("#table tr")
to
$("#table > tr")
thus ensuring that you select only direct child TRs and not all descendant ones.
精彩评论