views:

23

answers:

3

Markup:

<div class="foo">
    <img src="loading.gif" class="loading" style="display: none;" />
</div>

Js:

$("div[class='foo']").click(function(e) {
    e.preventDefault();
    $(this).hide();
    $(/* somehow select the loading img of exactly this div with class foo (not others) */).show();
});
+1  A: 

If you want any descendant of the given element you can use find():

$(this).find(".foo");

If you know you only want to search for the first-level children elements, you can use children():

$(this).children(".foo");
matt b
+2  A: 
$("div[class='foo']").click(function(e) {
    e.preventDefault();
    $(this).hide();
    $('img.loading', this).show();
});
simplyharsh
Wow! You can pass context to the $-selector! Nice.
randomguy
@randomguy: Selector context maps to the *find()* method, so `$('img.loading', this)` is the same as `$(this).find('img.loading')`. Selector context is much "nicer", I think.
Andy E
A: 

You could use

$(this).find("img").show();

or

$(this).find("img.loading").show();