views:

84

answers:

3
$("#start").find(divs where class=desc).show()

<div id="start">
<div class="desc" style="display:none;"></div>
</div>

How do I do that?

+7  A: 

Just like the jQuery() function, find() takes a CSS selector as an argument.

$("#start").find("div.desc").show();

find is the equivalent of context searching, so the above is the same as:

$("div.desc", "#start").show();

http://api.jquery.com/find/

Andy E
Are you sure those the same? The first would find a div with a class of 'desc' that has a parent of #start and then show it. The scond would find both any div with a class of 'desc' and #start and show them all.
DA
@DA: Selector context uses the `.find()` method anyway, so yes, they are the same. http://api.jquery.com/jquery/#selector-context
Andy E
@DA: the #start string is a second parameter, not part of the selector.
SBUJOLD
Is there a difference between $("div.desc, #start") and $("div.desc", "#start")? Maybe that's where I'm confused.
DA
@DA: Yes, comma separations inside a selector will combine the results of both selectors. Supplying a selector as a second parameter to the jQuery function tells jQuery to only search descendants of that elements matching that selector.
Andy E
@Andy ah! I never knew that! good to know!
DA
A: 
$("#start.desc").show();
Francisco Soto
That wouldn't be found given the sample markup.
DA
+1  A: 

Try:

$("#start").find("div.desc").show()
Justin Ethier