【发布时间】:2011-09-27 02:47:55
【问题描述】:
我正在尝试定位由 jQuery 插件生成的 div。我一直在尝试使用 .next 但没有运气。
更新:请注意这个生成的 div 是由点击触发的
*更新:这里是代码http://jsfiddle.net/clintongreen/PAbAH/1/
问题是,下一个选择器会忽略生成的 div 并以下一个 div 为目标。我知道这不起作用,因为生成的 div 在技术上不是兄弟。
有谁知道我如何定位这个难以捉摸的生成 div。我不能使用 css,因为我只想在它从某些链接生成时隐藏它。
代码示例
//Script
$("div.region_marker").next("div.bubble").hide();
//HTML
<div class="region_marker">Region Marker text</div> //this is how I am targeting the generated div
<div class="bubble">Bubble text</div> //div generated by jQuery, not hard coded, this is ignored by .next
<div class="map_marker">Map Marker text</div> //random div, this is the one that .next targets
<div class="map_marker">Map Marker text</div> //random div
我愿意接受您的任何建议,谢谢大家
【问题讨论】:
-
请发布您的代码。 jQuery是否添加元素应该没有区别。
-
必须有 more to it than meets the eye... (我猜插入脚本在 DOM 加载之后被调用,但你的脚本被称为 之前(所以它技术上当jQuery去寻找它时没有添加它)
-
代码对我来说看起来不错。会不会是时间问题?即当您执行代码时是否已经生成了气泡 div?
-
大家好,谢谢,我想你们可能生我的气了,因为我忘了提到 div.bubble 是通过点击生成的。我有一个针对 div.region_marker 坐标的链接,这也会触发 div.bubble 弹出窗口。很抱歉,我之前没有提到过。
-
我在这里发布了一个 jsfiddle,jsfiddle.net/clintongreen/PAbAH/1 这都是使用移动地图顺便说一句。干杯
标签: jquery