小编sur*_*raj的帖子

克隆div并删除类而不更改原始类

我想使用jQuery克隆div的内容,但是在我使用appendTo函数之前,我想从复制的内容中删除该类.当我从克隆中删除该类时,它们也会从原始类中删除.

我的代码是:

$('.carousel .item').each(function(){
        var next = $(this).next();

        if (!next.length) {
            next = $(this).siblings(':first');
        }
        next.children(':first-child').clone().appendTo($(this));
        next.children(':first-child').addClass('col-sm-offset-1');

        for (var i=0;i<3;i++) {
            next=next.next();
            if (!next.length) {
                next = $(this).siblings(':first');
            }
            next.children(':first-child').clone().appendTo($(this));                 
        }

});
Run Code Online (Sandbox Code Playgroud)

请注意,我不想从复制内容的实际div中删除类,我只是想从复制的代码中删除它,以便它不包含在克隆的div中.

javascript jquery twitter-bootstrap bootstrap-modal

5
推荐指数
1
解决办法
696
查看次数