简体   繁体   中英

jQuery adding / chaining elements to one variable

how can I turn this into something faster:

$.each(data, function(key, val) 
{ 
    rcItemsLi.eq(index++).append('<div class="rc-item-content clear hidden"><p class="rc-item-context">' + val[0] + '</p>' + val[1] + '</div>'); 
}); 
rcItemsContent = $('.rc-item-content');

in this example, I first append the elements to where I want, then I use .rc-item-content selector to "find" all the elements and store them in rcItemsContent variable.


for example:

$.each(data, function(key, val) 
{ 
    rcItemsContent.add($('<div class="rc-item-content clear hidden"><p class="rc-item-context">' + val[0] + '</p>' + val[1] + '</div>').appendTo(rcItemsLi.eq(index++))); 
});

in this example, what I'm trying to achieve (which of course I don't), is to add / chain the element in the variable and append it to where I want at the same time.

.add创建一个新集合。

rcItemsContent = rcItemsContent.add(...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM