Подтвердить что ты не робот

Как я могу сделать sub selects на уже выбранном элементе?

Разметка:

<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();
});
4b9b3361

Ответ 1

$("div[class='foo']").click(function(e) {
    e.preventDefault();
    $(this).hide();
    $('img.loading', this).show();
});

Ответ 2

Если вам нужен любой потомок данного элемента, вы можете использовать find():

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

Если вы знаете, что хотите только найти элементы первого уровня для детей, вы можете использовать children():

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

Ответ 3

Вы можете использовать

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

или

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