开发者

How can I do sub selects on already selected element?

开发者 https://www.devze.com 2023-01-10 22:30 出处:网络
Markup: <div class=\"foo\"> <img src=\"loading.gif\" class=\"loading\" style=\"display: none;\" />

Markup:

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

Js:

$("div[class='foo']开发者_StackOverflow").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();
});


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");


You could use

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

or

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

精彩评论

暂无评论...
验证码 换一张
取 消