gpt4 book ai didi

jQuery:获取 parent , parent ID?

转载 作者:IT王子 更新时间:2023-10-29 03:26:33 25 4
gpt4 key购买 nike

<ul id ="myList">
<li><a href="www.example.com">link</a></li>
</ul>

如何使用 jQuery 获取 ul (myList) 的 ID?单击链接时会触发我的 j-script 事件。我试过:

$(this).parent().attr('id');

但它获取了 li 的 id,我需要更上一层,我也无法将点击附加到 li。

最佳答案

$(this).parent().parent().attr('id');

您将如何获得 parent 的 parent 的 ID。

编辑:

$(this).closest('ul').attr('id');

对于您的案例来说是一个更简单的解决方案。

关于jQuery:获取 parent , parent ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10260667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com