How to make div editable which is created dynamically

拥有回忆 提交于 2019-12-23 19:49:33

问题


I want to make div editable which is created dynamically. Which is also draggable 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!


回答1:


Since you are having a dynamically created div use .on() handler for it and .prop():

  $(document).on("click", "#divid", function(){
     $(this).prop('contentEditable',true);
  });

find out in fiddle: http://jsfiddle.net/SEvDe/




回答2:


Fiddle

$("#test").get(0).contentEditable = "true";
$("#test1").attr('contentEditable',true);

It works as a charm.

with javascript u could have tried this

document.getElementById("contentDiv").contentEditable = "true";


来源:https://stackoverflow.com/questions/14156371/how-to-make-div-editable-which-is-created-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!