views:

77

answers:

4

On rolling over a wrapper div, I need different nested children to do different things.

One div needs to fade to one level of opacity, another div needs to do another thing.

It's all wrapped in quite a lot of stuff that i can't tamper with.

I have NO idea how to call children in children.... I have tried every frikkin combo of jQuery but it just does not want to play, because it's getting hitched on the 'this' part of the function.

But if I take away the 'this' it does the action to all instances in the document.

<div class="vpMedia"><li><a href="http://site.com"&gt;&lt;div class="vpArrow"><image src="http://site.com/image1"&gt;&lt;/div&gt;&lt;div class="vpLeft">Title</div><div class="vpRight">
<div class="vpRightImg"><image src="http://site.com/image2"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/a&gt;&lt;/li&gt;&lt;/div&gt;

I've searched everywhere for questions or topics related to finding a child in a child but alas, there is really nothing around. I've seen nothing like:

this.children(.foo).children(#bar)

Or maybe going this route?

this > .foo > #bar

Because it would never work, the 'this' needs to be out of quotation marks. So whats the solution if we cant use em?

Edit - OK so this is a really newbie question. Sorry, hopefully will help a beginner out there somewhere. Thanks for your patience.

A: 

I believe $(this).find() will work for this.

Check out http://api.jquery.com/find/ for more information on find.

Chris
+1  A: 

To call children of children you can do:

$(this).children(".foo").children("#bar");

or you can use find which is similar to children except that it scans the DOM recursively.

$(this).find("#bar");
Dustin Laine
WORKED! Thanks :-)I love this find selector
RGBK
Keep in mind that the `find` in not the most efficient method as it is recursive. If searching for a ID, which should be unique, I would do at @AKX said above.
Dustin Laine
+2  A: 

Tried $(".foo>#bar", this) or $(this).children('.foo').children('#bar')?

Also, remember that legally IDs should be unique within a page, so that example could be written just $('#bar')...

AKX
+1 good point on the unique ID.
Dustin Laine
+2  A: 

You need to do .children('.vpLeft') , not .children('vpLeft'). You are selecting an element whose nodeName === 'vpLeft'.

$("div .vpMedia").mouseover(function() {
    $(this).children("li").children("a").children(".vpLeft").animate({opacity: .3}, { duration: 100, queue: false });
}).mouseout(function() {
    $(this).children("li").children("a").children(".vpLeft").animate({opacity: 1}, { duration: 100, queue: false });
})

You can shorten it..

$("div .vpMedia").mouseover(function() {
    $('>li>a>.vpLeft', this).animate({opacity: .3}, { duration: 100, queue: false });
}).mouseout(function() {
    $('>li>a>.vpLeft', this).animate({opacity: 1}, { duration: 100, queue: false });
})

Also it's <img> not <image>

meder