Within my editable div, I have incorporated the use of :before and :after CSS pseudo-elements.
The :before pseudo-element displays a prompt inside the div,
while the :after pseudo-element acts as a placeholder
When a user clicks on an empty div, the cursor is placed before the "prompt" text.
As soon as the user starts typing, the :after content vanishes, ensuring the cursor is correctly positioned.
I am seeking a method to automatically position the cursor after the content when selecting an empty div. Interestingly, if there is any existing text in the div and it is selected, the cursor goes to the end as desired.
I would greatly appreciate any thoughts or assistance with this.
div[data-prompt][contenteditable=true]:before {
content: attr(data-prompt);
font-family: 'Open Sans', sans-serif;
color: black;
}
div[data-placeholder]:empty:after {
content: attr(data-placeholder);
color: black;
}
<div contenteditable='true' id="tbl01_r2c2" data-type="2" data-prompt="I will " data-placeholder="..."></div>
Cursor positioning behavior when an empty div is selected
https://i.sstatic.net/dEIkN.png
Please note that the length of the "prompt" may vary.