<div class="apple">
<div class="abc">
<input id="go">
</div>
</div>
$("#go").click(function(){
$(this).parent('.apple').hide(); // this doesn't work.
$(this).parent().parent().hide(); //this works
});
Run Code Online (Sandbox Code Playgroud)
我想要.parent('.apple')
工作.
[...] .parents()和.parent()方法类似,只是后者只在DOM树上运行一个级别.[...]
换句话说,使用jQuery.parents()
而不是jQuery.parent()
.
归档时间: |
|
查看次数: |
73 次 |
最近记录: |