【发布时间】:2011-11-10 00:32:42
【问题描述】:
请指导我如何使用 jQuery 找到特定的 div 来跟踪 html -
<div class="tab_container">
<div id="tabs-1111" class="tab_content" style="display: block;">
<p>26 High Street, Slough, SL1 1EP</p>
<p></p>
</div>
<div id="tabs-1110" class="tab_content" style="display: none;">
<p></p>
<p></p>
<div id="GoogleMap_Canvas"
style="width: 410px; height: 450px; position: relative; overflow: hidden;">
<p></p>
</div>
</div>
</div>
我想检查具有“tab_content”类的第一个 div 是否包含 id = 'GoogleMap_Canvas' 的 div - 对于上面的 html,这应该是错误的,因为它在第二个 div 中。
我尝试使用 -
if ($(".tab_content:first").children('#GoogleMap_Canvas').length > 0)
or
if ($(".tab_content:nth-child(1)").children('#GoogleMap_Canvas').length> 0)
这对我来说似乎工作得很好。
但是,我很困惑为什么跟随 jQuery 返回 null?
($(".tab_content")[1]).children('#GoogleMap_Canvas') //returns null
谢谢!
【问题讨论】:
标签: jquery