href标签上发生点击事件,需要引用向上9级的a的类,
所以:
<div class="blah" id="234">
<div>
<div>
<div>
<div>
<div>
<div><a href=""></a>
我知道的唯一方法就是调用parent() 9次,我还能做什么?
最佳答案
您可以通过Parents函数提供选择器
$(a).click(function() {
var theIdIs = $(this).parents("div.blah").attr("id");
});
关于jquery - 在 jQuery 中向上遍历 9 层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/572926/