我有这个 jQuery 代码:
$(this).closest('div:has(.FIND_ME)').find('.FIND_ME').hide();
但是类 .FIND_ME
的元素不会在 IE8 和 9 中隐藏。
这个问题是Search for an item with a common ancestor的延续
HTML:
<div>
<div><!-- all div without ID -->
<span>some text</span>
<div>
<span id="listener1">click here</span>
<span>sometext</span></div>
<div>
<span class="FIND_ME">Result Here</span></div>
</div>
<div>
<span>some text</span>
<div id="div1">
<div id="div2">
<span id="listener2">click here</span>
<span>sometext</span></div>
</div>
<div>
<span class="FIND_ME">Result Here</span></div>
</div>
</div>
最佳答案
我将变量 element
设置为 this
,然后我调用了:
element.closest('a')
但是元素现在是 DOM 元素而不是 jQuery 对象。所以改为:
$(element).closest('a')
修复它。
关于javascript - jQuery 的 closest 在 IE8/9 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28041056/