开发者

jQuery - make all table cells draggable except first cell in each row

I cannot figure out how to make all cells in a table draggable, except the first cell in each row. I thought this might work:

$("#tableid tbody tr td:not(:first)").draggable({
    connectToSortable: "#sortable",
    helper: "clone",
    revert: "invalid"
});

Or this:

$("#tableid tbody tr td").not("#tabl开发者_StackOverflow社区eid tbody tr td:first").draggable({
    connectToSortable: "#sortable",
    helper: "clone",
    revert: "invalid"
});

But both just stops the first cell of the first row being draggable. Not every row...

Any ideas?


To select all but the first td per row, you want:

$('#tableid tbody tr').find('td:gt(0)')

Test it out here: http://jsfiddle.net/KsUCj/

By calling :first you are finding the first element in the entire set.

Also, if you are treating the first cell in each row as special, it sounds like you might actually want this markup instead:

<table><thead><tr>
  <th></th>
  <th scope="col">Column Head 1</th>
  <th scope="col">Column Head 2</th>
</tr></thead><tbody><tr>
  <th scope="row">Row Head</th>
  <td>Row Cell 1</td>
  <td>Row Cell 2</td>
</tr><tr>
  <th scope="row">Row Head</th>
  <td>Row Cell 1</td>
  <td>Row Cell 2</td>
</tr></tbody></table>

Not only is this more semantic, and provides you better hooks for your CSS styling of the row heads, but you would not have run into this problem as tbody tr td would select all but the first column already.


Shouldn't that be 'tr:first td' as opposed to 'tr td:first'?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜