Why does my jQuery click function not do anything?
Here is my HTML
<table>
<tbody>
<tr id="taskID-1">
<td>
<a href="#" class="edit">edit</a>
</td>
<td data-field="complete">
<input type="checkbox" name="ta开发者_如何学Csks" id="checkID-1">
</td>
<td data-field="description" colspan="100">
<label for="checkID-1">Description of task numero uno.</label>
</td>
</tr>
<tr id="taskID-2">
<td>
<a href="#" class="edit">edit</a>
</td>
<td data-field="completed">
<input type="checkbox" name="tasks" id="checkID-2" value="Description of task number 2" checked="checked">
</td>
<td data-field="description" colspan="100">
<label for="checkID-2" class="line-through">Description of task number 2.</label>
</td>
</tr>
<tr class="add">
<td colspan="100">
<a href="#">add task</a>
</td>
</tr>
<tr class="editRow">
<td>
<a href="#" class="cancel">cancel</a>
</td>
<td> </td>
<td>
<input type="text" class="description">
</td>
<td>
<menu class="saveButtons">
<a href="#" class="save close">save</a>
<a href="#" class="delete">delete</a>
</menu>
</td>
</tr>
</tbody>
</table>
Here is my jQuery:
$('.add a').live('click', function() {
// hide the .add row and show the .editRow
$(this).closest('table').children('.edit').hide();
$(this).closest('table').children('.add').hide();
$(this).closest('table').children('.editRow').fadeIn();
return false;
});
Because the only child of table
is tbody
and it has neither class edit
nor add
or editRow
. You might want to use find
instead:
$(this).closest('table').find('.edit').hide();
$(this).closest('table').find('.add').hide();
$(this).closest('table').find('.editRow').fadeIn();
But as I don't know what you actually want to achieve I cannot say if this is doing what you want ;)
精彩评论