Ответ 1
$("div[class='foo']").click(function(e) {
e.preventDefault();
$(this).hide();
$('img.loading', this).show();
});
Разметка:
<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();
});
$("div[class='foo']").click(function(e) {
e.preventDefault();
$(this).hide();
$('img.loading', this).show();
});
Если вам нужен любой потомок данного элемента, вы можете использовать find():
$(this).find(".foo");
Если вы знаете, что хотите только найти элементы первого уровня для детей, вы можете использовать children():
$(this).children(".foo");
Вы можете использовать
$(this).find("img").show();
или
$(this).find("img.loading").show();