[英]jQuery - each() on cloned element
我正在尝试对克隆的元素做一个each()
,
var html = $(this).clone().html();
html.find('.class').each(function () {
$(this).removeClass('class-to-remove');
});
console.log(html);
但是当我在控制台中看到var html
,它将显示先前的值,而不是each()
完成后的值。
请告诉我如何在完成each()
位置获取var。
.html()
的返回值是一个字符串 。 在这种情况下,最好不要完全调用它。 只需使用.clone()
的返回值.clone()
。
var cloned = $(this).clone();
cloned.find('.class').each(function() {
$(this).removeClass('whatever');
});
console.log(cloned.html());
另请注意, .html()
获取其操作数的内容 ,因此不会显示外部“外壳”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.