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 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>
Share
Improve this question
edited Nov 9, 2017 at 2:38
Undo♦
25.7k38 gold badges112 silver badges131 bronze badges
asked Jan 20, 2015 at 8:52
DmitMedvDmitMedv
1,0103 gold badges13 silver badges22 bronze badges
9
|
Show 4 more comments
3 Answers
Reset to default 15I 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);
};
You're right! I don't know why, but it works now! The mistake was in an another place.
Thus, closest()
works fine in IE 8/9. Tested on jQuery 1.6.
closest()
works fine in IE8/9. The issue will lie in your code somewhere. Please add your relevant HTML to the question. – Rory McCrossan Commented Jan 20, 2015 at 8:53