克隆后查找并添加文本会产生错误的输出

时间:2015-02-07 04:55:10

标签: jquery

我想克隆一个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);
            }

0 个答案:

没有答案