我想克隆一个div,之后我想找到一个更新文本的元素。我喜欢这个:
constructRightNavi : function () {
var cloneCategory = null;
if(!this.sideBar.find('#'+this.category).length)
cloneCategory = categoryHolder.clone()
.removeClass('hide')
.prop('id', this.category)
.find('.text')
.text(this.category);;
this.sideBar.find('.queryWrapper').before(cloneCategory);
}
但是在输出中,一切都消失了
我将输出作为最后一个已发现的元素,如下所示:
<span class="text">Mechanical</span>
如何克隆和更新元素?
更新
如果我像这样更新,它就可以了!
if(!requiredCategory.length) {
this.clonedCategory = categoryHolder.clone()
.removeClass('hide')
.prop('id', this.category);
this.clonedCategory.find('.text').text(this.category); //after clone finding works
this.sideBar.find('.queryWrapper').before(this.clonedCategory);
}