将动态dom元素绑定到content.js插件

我有一个插件,我正在使用被称为content.js http://innovastudio.com/content-builder.aspx

我添加动态div到页面,我想分配给它的content.js插件,所以我可以利用它的function。

在单个div或页面中已经定义的div上,我似乎没有多个div的任何问题。

但是,如果我添加一个具有相同类的div,我似乎无法将插件绑定到它。

我已经包含了使用contentbuilder插件实例化div的代码,但我想知道是否有办法将它绑定到添加到“letter”类的页面的新元素。 或者,如果有一种使用jquery将插件绑定到div的通用方法。

$('div.letter').contentbuilder({ enableZoom:false, snippetOpen: true, imageselect: 'images.html', fileselect: 'images.html', snippetFile: '/assets/templates/content-builder/default/snippets.html', toolbar: 'left', //sourceEditor: false, onDrop:function(){ // function for when an item is dragged into the editable area }, onRender: function () { var coverLength = $("#coverpage div.row").length; var mainContent = $("#maincontent div.row").length; if(coverLength == 0) { $("#coverpage").html('
Select your content from the right sidebar
') } else { $("#coverpage div.no-content-on-page").remove(); } if(mainContent == 0) { $("#maincontent").html('
Select your content from the right sidebar
') } else { $("#maincontent div.no-content-on-page").remove(); } //custom script here } });

如果你必须以dinamic方式添加这些div,我认为你应该在每次添加新div时初始化插件。 要避免初始化相同的div两次,请使用类似以下示例中的类:

 function createLetter(){ $("body").append('
'); initContentBuilder(); } function initContentBuilder(){ $('div.letter.mustBeActivated').contentbuilder({ enableZoom:false, snippetOpen: true, imageselect: 'images.html', fileselect: 'images.html', snippetFile: '/assets/templates/content-builder/default/snippets.html', toolbar: 'left', //sourceEditor: false, onDrop:function(){ // function for when an item is dragged into the editable area }, onRender: function () { var coverLength = $("#coverpage div.row").length; var mainContent = $("#maincontent div.row").length; if(coverLength == 0) { $("#coverpage").html('
Select your content from the right sidebar
') } else { $("#coverpage div.no-content-on-page").remove(); } if(mainContent == 0) { $("#maincontent").html('
Select your content from the right sidebar
') } else { $("#maincontent div.no-content-on-page").remove(); } //custom script here } }).removeClass('mustBeActivated'); }