views:

40

answers:

4

Hi,

i have this function :

jQuery.fn.getParent = function(num) {
var last = this[0];
for (var i = 0; i < num; i++) {
    last = last.parentNode;
}
return jQuery(last);
};

and this html :

<div class="statuscontainer">
<div class="title">
Title of div here
</div>
blah blah blah blah <br>
<a onclick="$(this).getParent(4).fadeTo("slow",.3);">fade only this div</a>
</div>


<div class="statuscontainer">
<div class="title">
Title of div here
</div>
blah blah blah blah <br>
<a onclick="$(this).getParent(4).fadeTo("slow",.3);">fade only this div</a>
</div>

what i want, that each link should fade it's main statuscontainer div and not all other divs, that's done using jQuery GetParent.

that's works great in firefox/chrome/safari, but in IE 7/8 , only the blah blah blah and the link are faded and not the entire "statuscontainer".

What do you suggest ?

Thanks

A: 

why not just use jQuery('theElementSelector').parents(':eq(3)'); note i didnt look what index you were actually after but it should be 3 or 4 depending.

prodigitalson
thanks for answer, the problem which i just realized that some other divs inside storycontainer are not fading! i don't know why only in IE
axel gold
+1  A: 

I can't see what's wrong in the code, it seems straightforward enough.

Maybe using one of these JQuery functions helps?

I'm assuming that being core functions of JQuery, any cross-browser issues are likely to have been resolved there.

Pekka
They do indeed :-)
prodigitalson
I hate to admit it, but JQuery *is* damn good. :)
Pekka
thanks for answer, the problem which i just realized that some other divs inside storycontainer are not fading! i don't know why only in IE
axel gold
Maybe it's because they don't have layout (try the `zoom: 1` CSS property) or something along that line? IE often has issues fading elements.
Pekka
The search yields a lot of results http://stackoverflow.com/search?q=IE+fade
Pekka
A: 

I would suggest using $(this).closest('.statuscontainer').fadeTo() instead. That way no matter where the <a> is in the DOM - it will find the closest .statuscontainer in the parents. .closest() docs

gnarf
thanks for answer, the problem which i just realized that some other divs inside storycontainer are not fading! i don't know why only in IE
axel gold
A: 

Thanks all, i found the solution , some divs which are not faded, are positioned in "relative", once i deleted the positioning , it worked :)

Thanks

axel gold