$("input[name='add'].my").click(function(){
//i tried use this <input type="button" name="add" value=..../>
//element to find his parent's parent the `<div>` object
//how can i get it
});
<div>
<tr>
<td><%= post.title %></td>
<td><%= post.content %></td>
<td><%= link_to 'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post),:remote=>true %></td>
<td><%= link_to 'Destroy', post, :confirm => 'Are you sure?',:remote=>true, :method => :delete %></td>
<td><input type="button" name="add" value="add" class="my"/></td>
<td></td>
</tr>
</div>
<div>
<tr>
<td><%= post.title %></td>
<td><%= post.content %></td>
<td><%= link_to 'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post),:remote=>true %></td>
<td><%= link_to 'Destroy', post, :confirm => 'Are you sure?',:remote=>true, :method => :delete %></td>
<td><input type="button" name="add" value="add" class="my"/></td>
<td></td>
</tr>
</div>
答案 0 :(得分:3)
这将为您提供最近的父div:
$("input[name='add'].my").click(function(){
var parentDiv = jQuery(this).closest("div");
});
答案 1 :(得分:1)
你走了:
$(function() {
$("input[name='add'] .my").click(function(){
var parent = $(this).parent().parent().parent();
//OR
var parent = $(this).closest('div');
//do stuff...
});
});