Nearest jQuery not working in IE8 / 9

I have this jQuery code:

$(this).closest('div:has(.FIND_ME)').find('.FIND_ME').hide(); 

But an element with class .FIND_ME not hidden in IE8 and 9.

This question is a continuation of the 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> 
+6
source share
3 answers

I set the element variable to this , and then I called:

 element.closest('a') 

But the element was now a DOM element instead of a jQuery object. So change to:

 $(element).closest('a') 

fixed it.

+11
source

You're right! I don’t know why, but now it works! The error was elsewhere.

Thus, closest() works fine in IE 8/9. Tested on jQuery 1.6.

0
source
 closest = function (target, tag) { if (target.parentElement == "undefined") { return null; } if (target.parentElement.localName == tag) { return target.parentElement; } return this.closest(target.parentElement, tag); }; 
0
source

Source: https://habr.com/ru/post/981257/


All Articles