简体   繁体   English

jQuery向一个变量添加/链接元素

[英]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. 在这个例子中,我首先将元素追加到我想要的位置,然后使用.rc-item-content选择器“查找”所有元素并将它们存储在rcItemsContent变量中。


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(...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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