开发者

jQuery children from jQuery selected object?

开发者 https://www.devze.com 2023-01-23 18:57 出处:网络
So here is code what I have. var template = $(\"#instance > .template\"); $(\"#instance-\" + country + \" > .content > .stats > .map > .template\").before(function() {

So here is code what I have.

var template = $("#instance > .template");
$("#instance-" + country + " > .content > .stats > .map > .template").before(function() { 
    var temp = template.clone();

    //ho开发者_StackOverflow中文版w to select descendant?
    temp.children(".amount-all").html(json.services[service].total);

    return temp;
});

Do I need to do like this:

temp.children(".amount-all").children("blala").children("blalalala").html("blala");

Or is there other, easier way?


You can use .find() to get decendants that match the selector at any level (as opposed to looking at just immediate children like .children() does), like this:

temp.find(".amount-all").html(json.services[service].total);
0

精彩评论

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