I have this jQuery code:
$(this).closest('div:has(.FIND_ME)').find('.FIND_ME').hide();
But element with class .FIND_ME
doesn't hide in IE8 and 9.
This question is a continuation of 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>
I was setting a variable element
to this
, then later on I was calling:
element.closest('a')
But element was now the DOM element instead of the jQuery object. So changing to:
$(element).closest('a')
fixed it.
closest = function (target, tag) {
if (target.parentElement == "undefined") {
return null;
}
if (target.parentElement.localName == tag) {
return target.parentElement;
}
return this.closest(target.parentElement, tag);
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With