I have the following code demonstrating contenteditable property and a button that will inject bold text into the paragraph with contenteditable area. My question is how to retu
You may want to store the last clicked item in a variable and then call .focus() on it after the .execCommand has been executed. Something like this, I guess:
$(function(){
$('p.editable').click(function() {
var clickedItem = $(this);
clickedItem.attr('contenteditable', true).focus();
$('#bold').click(function (){
document.execCommand('bold', false, true);
clickedItem.focus();
});
});
});
This way you can also remove the "contenteditable"
attribute from the markup...
HTH