观看元素和更改文本的脚本

时间:2013-03-23 20:34:21

标签: jquery

我正在使用bootstrap editable来编辑照片的文本属性。默认情况下,它显示文本,如果单击它,则会打开带有可编辑文本的小窗口。我想要做的就是创建一个脚本,用铅笔图标替换文本。我写了这个:

$('#gallery').delegate('.editable-click', 'need_some_event' , function(){
    $(this).text();
    $(this).html('<i class="icon-pencil" ></i>');
}); //end delegate

我的代码:

<a class="edit editable editable-click" style="float:left; margin-right: 10px" href="#" rel="Photo_text_183" data-pk="183">some text descrtion of photo</a>

我想要的是:

<a class="edit editable editable-click" style="float:left; margin-right: 10px" href="#" rel="Photo_text_183" data-pk="183"><i class="icon-pencil" ></i></a>

问题是,可编辑文本是由另一个javascript生成的。我基本上需要一些事件来观看所有.editable-click类元素,如果它们出现,请删除带有图标的文本。谢谢你的任何建议。

1 个答案:

答案 0 :(得分:2)

也许你可以尝试听DOMNodeInserted

$(document).on('DOMNodeInserted', function(){
if($(this).find('.editable-text').length > 0){
//do stuff 
}
});

这是一个工作小提琴作为例子http://jsfiddle.net/wvVnQ/1/

由于如下所述,我们不推荐使用此插件:https://github.com/naugtur/insertionQuery