How to make div editable which is created dynamica

2019-07-06 16:44发布

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!

2条回答
虎瘦雄心在
2楼-- · 2019-07-06 17:03

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/

查看更多
劳资没心,怎么记你
3楼-- · 2019-07-06 17:09

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";
查看更多
登录 后发表回答