3

Solved. The answer to the question bellow was given to me by @freedomn-m and to found there: Set focus on div contenteditable element

For a Rich Text Editor using an editable div: I wish the caret to be showing again in the div after, for example, a click on the font size selector. I thought that giving back the focus to the div would be enough but it isn't. Maybe I could save the position of the caret and set it back at its right position after the interruption. But something tells me there must be a much easier way to do that... Maybe something in jquery? So far I've got that:

$("#fontSizeChanger").change(function(){
    var newSize = $("#fontSizeChanger").val();
    $("#editor").css("font-size", newSize);
    $("#editor").focus();
});

"fontSizeChanger" is the id of a drop-down box and "editor" the id of the div.

Any ideas?

Update: What I really want is to see the caret blinking in the div after for example I clicked on a button outside of it.

Didier Tibule
  • 101
  • 1
  • 11
  • 2
    Please post your HTML too. – AndrewL64 Jan 31 '19 at 09:18
  • Possible duplicate of [Set focus on div contenteditable element](https://stackoverflow.com/questions/2388164/set-focus-on-div-contenteditable-element) – freedomn-m Jan 31 '19 at 09:25
  • @freedomn-m okey. I don't understood. – doğukan Jan 31 '19 at 09:27
  • See also the last comment on this answer (same Q as dupl) which implies that the drop down change event is changing the focus *back* after you change it to the div: https://stackoverflow.com/a/37162116/2181514 – freedomn-m Jan 31 '19 at 09:27
  • @DogukanCavus no worries :) – freedomn-m Jan 31 '19 at 09:27
  • Regarding the update: if you have focus in another control (eg a drop down (` – freedomn-m Jan 31 '19 at 09:39
  • @freedomn-m. Hmmm maybe I'm not explaining well. If you take a text editor; say MS Word. If I select a font, a size, bold, italic... After the change has been made, the drop-down closed, the button clicked the focus returns to the edited document and the cared keep blinking where it was before. what i have at the moment is my caret to disappear and I need to click in the editable div to have it showing again. seems a little thing but I would like to keep my caret showing after any click outside the editable zone... – Didier Tibule Jan 31 '19 at 09:47
  • 1
    Yes, that part makes perfect sense. The bit that didn't make sense was to select an element outside the div and still have the div flashing (I may have misinterpreted the edit). Using your Word example, if you click in the font-selector box where you can type in the font, the flashing caret disappears from the main document 'canvas' and when you select the font you want, the caret reappears as focus returns to the document itself. You can do this with the answer in the question I linked above. – freedomn-m Jan 31 '19 at 09:51
  • 1
    @freedomn-m. Thanks! It works just fine :) – Didier Tibule Jan 31 '19 at 10:05

0 Answers0