2013-05-02 34 views
0

提交表單我無法使用.closest()方法提交表單。無法使用.closest()

這裏是我的HTML:

<div class="avatar"> 
    <form method="POST" action="out" accept-charset="UTF-8"> 
     <input type="hidden" name="id" value="9"> 
     <img src="img/avatars/698dc19d489c4e4db73e28a713eab07b.jpg" class="img-rounded"> 
    </form> 
</div> 

這裏是我的JS:

$(".avatar").bind('click',function(){ 
    $(this).closest("form").submit(); 
}) 

如果我使用的ID,而不是類,它的工作原理。

謝謝。

+0

@MohammadAdil父 – 2013-05-02 21:41:47

+2

您的形式是化身的一個孩子,所以你要''find' children' – billyonecan 2013-05-02 21:41:54

+0

類=「阿凡達」 .. – 2013-05-02 21:42:00

回答

1

使用children方法和你正在做或

$(".avatar").bind('click',function(){ 
    $(this).children("form").submit(); 
})