我正在使用 jQuery.append()动态添加一些元素。有什么方法可以获取这些新插入元素的 jQuery 集合或数组吗?
所以我想这样做:
$("#myDiv").append(newHtml);
var newElementsAppended = // answer to the question I'm asking
newElementsAppended.effects("highlight", {}, 2000);
最佳答案
有一种更简单的方法可以做到这一点:
$(newHtml).appendTo('#myDiv').effects(...);
这通过首先使用 jQuery(html [, ownerDocument ])
创建 newHtml
来扭转局面。 , 然后使用 appendTo(target)
(注意“To
”位)将其添加到 #mydiv
的末尾。
因为您现在开始 $(newHtml)
appendTo('#myDiv')
的最终结果是新的 html ,.effects(...)
调用也将在 新 html 上。
关于jQuery append() - 返回追加的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2159368/