I try to close the parent container when the internally nested button is clicked. In my user interface - I have many of these parent containers (I am looking at the preview windows of my product catalog on the product category page).
As you can see from my markup below, the CLOSE button is deeply embedded in the DOM. When the user presses the CLOSE button, I need to hide () the parent Box-1. Keep in mind that there can be up to 100 products displayed per page (100 Box-1 boxes at a time).
My markup is as follows:
<div class="box-1"> <div class="box-2"> <div class="box-3">...</div> <div class="box-4"> <div class="box-5">...</div> <a class="btn-close" href="#">CLOSE</a> </div> </div> <div class="box-6"> <div class="box-7">...</div> <div class="box-8"> ... <div class="box-9">...</div> </div> </div> </div>
My question is: how do I best (and most efficiently) traverse the DOM to get box-1 and issue the .hide () method ... here is my existing code.
<script> $productsResultItems.delegate('.btn-close', 'click', function (e) { </script>
I originally tried to do this -
$this.parents().find('.hover-box-large').hide();
which turned out to be very slow in IE7 and IE8.
I found that adding more details on the selector improved performance by almost 100 times for IE7, but only 4 times faster in IE8 :( IE8 still requires about 200 ms to close the parent container. Where are all the other browsers now (Chrome, Safari, Firefox, and IE7) close the container in less than 20 ms.
$this.parents('div.hover-box-large').hide();
But is there a better choice method? Any special reason why IE8 is soooo bad in this type of upstream workaround ??
source share