Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inactivate contentEditable

I have a webpage with an img. Each time the user clicks on the img, it will generate a span tag with the contentEditable attribute set to true.

My problem is that if the user clicks on the img to add a span, clicks on the span (thus activating the editable zone), then clicks back on the img, it will add another editable span (desired effect) but it will also leave the first span in edit mode.

How can I change back the editable span into a normal span?

like image 933
Alain Avatar asked Dec 22 '11 12:12

Alain


1 Answers

You can remove the contenteditable attribute and the focus with jQuery like this:

$('span#id').removeAttr('contenteditable').blur();

If you want to style all spans that can be edited you can do it like this in CSS:

span[contenteditable] { } /* editable */
like image 194
js-coder Avatar answered Sep 21 '22 21:09

js-coder