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 oflive
– 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
2 Answers
Reset to default 7Since 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";