I want to make div editable which is created dynamically. Which is also draggable div .
我想制作动态创建的div editable。哪个也是可拖动的div。
This is what I tried
这就是我试过的
1)$("#divid").attr('contentEditable','true');
2)$("#divid").live("click",function(){
$(this).click('contentEditable',true);
});
3)$("#divid").click('contentEditable',true);
but none of the above working. Any idea how to make it working!
但上述工作都没有。知道如何让它工作!
Thanks in advance!
提前致谢!
2 个解决方案
#1
7
Since you are having a dynamically created div use .on()
handler for it and .prop()
:
由于您正在使用动态创建的div,因此使用.on()处理程序和.prop():
$(document).on("click", "#divid", function(){
$(this).prop('contentEditable',true);
});
find out in fiddle: http://jsfiddle.net/SEvDe/
找出小提琴:http://jsfiddle.net/SEvDe/
#2
1
$("#test").get(0).contentEditable = "true";
$("#test1").attr('contentEditable',true);
It works as a charm.
它充当魅力。
with javascript u could have tried this
用javascript你可以尝试这个
document.getElementById("contentDiv").contentEditable = "true";
#1
7
Since you are having a dynamically created div use .on()
handler for it and .prop()
:
由于您正在使用动态创建的div,因此使用.on()处理程序和.prop():
$(document).on("click", "#divid", function(){
$(this).prop('contentEditable',true);
});
find out in fiddle: http://jsfiddle.net/SEvDe/
找出小提琴:http://jsfiddle.net/SEvDe/
#2
1
$("#test").get(0).contentEditable = "true";
$("#test1").attr('contentEditable',true);
It works as a charm.
它充当魅力。
with javascript u could have tried this
用javascript你可以尝试这个
document.getElementById("contentDiv").contentEditable = "true";