最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make div editable which is created dynamically - Stack Overflow

programmeradmin1浏览0评论

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!

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!

Share Improve this question asked Jan 4, 2013 at 11:32 sandipsandip 3,2895 gold badges34 silver badges54 bronze badges 3
  • once try on instead of live – Mr_Green Commented Jan 4, 2013 at 11:34
  • @Mr_Green I tried but not working – sandip Commented Jan 4, 2013 at 11:37
  • Ok I thought it might work as live is deprecated in newer versions of jquery. – Mr_Green Commented Jan 4, 2013 at 11:38
Add a ment  | 

2 Answers 2

Reset to default 7

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/SEvDe/

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";
发布评论

评论列表(0)

  1. 暂无评论