Html5 Contenteditable With Jquery
Solution 1:
$('#container *').attr('contenteditable','true');
*
means "all element types", and is analogous to a,div,span,ul,etc...
Like most other jQuery functions, attr applies the same operation to every element captured by the selector.
Solution 2:
Solution 3:
I get the impression you're misunderstanding the problem in two places:
jQuery creates "query" objects which provide a shorthand for manipulating sets of DOM elements. Your example code sets contentEditable on the query, not what it matches. You want jQuery's shorthand for "set an attribute on all matching elements", which is
$('whatever').attr('contentEditable','true');
I'm not sure you understand contentEditable properly. You're supposed to set it on the top-level container for each editable region and its effects apply to everything within. In my experience, if setting contentEditable on
#container
or something like#container div.post
really isn't good enough, then you've got bigger problems.
Solution 4:
For some reason in IE10 only this seemed to work:
$('#container').get(0).contentEditable = "true";
Why attr didn't work I do not know.
Solution 5:
If I can remember correctly, setting the contentEditable
value on the parent would also cause all its children to become editable.
So doing this:
$('#container').attr("contentEditable", "true");
Should work.
Post a Comment for "Html5 Contenteditable With Jquery"