Pavan Keerthi
Pavan Keerthi

Reputation: 1681

HTML5 ContentEditable not working in Chrome

I am building a HTML5 webapp and I tried using contenteditable feature to make a in-place edit of text,but for some reason I couldn't get "editing" to work.

EDIT: I am using Chrome 12.0.xx

With some clue in question How do I figure out why the contenteditable attribute doesn't work? I tried turning off of all CSS but no luck.

The only thing is, I am adding my elements via javascript rather that HTML source

JS Code:

var newLi =document.createElement("li");
var newLable=document.createElement("lable");
newLable.className="labletext";
newLable.contentEditable="true";
newLable.innerText=String(localStorage["task."+i+".taskValue"]);
newLable.addEventListener('blur',editTask,false);
newLi.appendChild(newLable);
Parent.appendChild(newLi);

function editTask()
{
   var keyid=this.id;
   var startchar = keyid.lastIndexOf("_");
   var endchar=keyid.length;        
   var taskId=parseInt(keyid.substring(startchar+1,endchar));

   localStorage.setItem("task."+taskId+".taskValue",this.innerText);
   loadTasks("tasklist");
}

Upvotes: 3

Views: 8513

Answers (2)

Pavan Keerthi
Pavan Keerthi

Reputation: 1681

For anyone coming later here,I Found the issue.I also enabled draggable attribute on <li> hence click event is hijacked by <li> events before reaching <label> child. Its answered here How can I enable 'draggable' on a element with contentEditable?.

Upvotes: 2

Šime Vidas
Šime Vidas

Reputation: 185883

It's

document.createElement('label')

not 'lable'

Live demo: http://jsfiddle.net/XuAfA/1/

The demo shows that the LABEL is editable.

Upvotes: 4

Related Questions