gpt4 book ai didi

jquery - 如何从 JQuery 中给定的 HTML 中获取 DIV ID

转载 作者:行者123 更新时间:2023-12-01 03:54:07 25 4
gpt4 key购买 nike

我有以下 HTML 格式:

<ul class="whatlike-list">
<li class="first">
<a href="/SessionHandler.aspx" class="button-flight-search">Search for Flights</a>
<div class="open-block-holder">
<div id="slideFlightSearch" class="open-block" style="display: block; left: 650px;">

</div>
</div>
</li>
</ul>

现在我希望通过点击链接“搜索航类”获得 DIV ID="slideFlightSearch",我已经获得了“button-flight-”类在我的 $this 对象中搜索”。我的 JQuery 中如下所示。

$(link).click(function()
{
alert($(this).attr("class"));
})

在上面的警报中,我得到了“button-flight-search”类,但是我需要内部 DIV ID slipFlightSearch

请建议使用 JQuery。

最佳答案

您可以使用.next.find ,像这样:

$(link).click(function() {
var id = $(this).next(".open-block-holder")
.find("div") // or .find("div.open-block")
.attr("id");
});

关于jquery - 如何从 JQuery 中给定的 HTML 中获取 DIV ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4773618/

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