I have a table I'm using jQuery UI's "sortable" on. In the table, I have rows consisting of a "drag handle" to grab and reorder the table, and cells with clickable items, like this:
<table id="test-table">
<tbody>
<tr>
<td class="handle"><div class="ui-icon ui-icon-arrowthick-2-n-s" /></td>
<td class="clickycell"><a href="#">Testing 1</a></td>
</tr>
<tr>
<td class="handle"><div class="ui-icon ui-icon-arrowthick-2-n-s" /></td>
<td class="clickycell"><a href="#">Testing 2</a></td></td>
<tr>
<td class="handle"><div class="ui-icon ui-icon-arrowthick-2-n-s" /></td>
<td class="clickycell"><a href="#">Testing 3</a></td></td>
</tr>
</tbody>
</table>
In my code, I make the table sortable, and also use jQuery's live() to bind a click event to the clickable items, like this:
$(function() {
/*
Using live() because in my real code table rows are dynamically added.
However, if I use click() instead, as in the commented-out code, it works
fine, without any need to click twice.
*/
// $(".clickycell a").click(function() {
$(".clickycell a").live('click', function() {
alert("Successful click");
return false;
});
$("#test-table tbody").sortable({
handle: "td.handle", /* Use the draggy handle to move, not the whole row */
cursor: "move"
});
});
I'm using live() because rows can be dynamically added to the table in the real code.
My problem is this: if I click on any of the clickable items before sorting, they work fine. After the user drags the rows to reorder them, though, I have to click twice for a click to register. After that second click, the clickable items go back to "normal", needing only one click, until the next time rows are dragged around.
If I use click() rather than live() -- as in the commented-out code -- then a single-click works fine at all times, but I'd rather use live(), as I said. And I'm curious as to why it's not working.
There's a live jsFiddle example here. Try dragging a row into a different position, then clicking on any of the "Testing..." links. In Firefox, at least, I need to click twice to get the "Successful click" alert.
Any ideas?