WORMSS
WORMSS

Reputation: 1664

Select contenteditable span

I have a multiple <span> with contenteditable, I am trying to programmatically "select" a <span> and force into editable mode. But it seems I am having a lot of trouble doing this.

With <input> I can use

element.select();

but a <span> obviously does not have this method.

I need to use <span> has the content is designed to be copy/pasted out with a bunch of uneditable content which <input> does not allow the mix and matching when selecting all the code.

I could do a bunch of funky work with putting the content of the <input> into a hidden <span> within the content that is being copied/pasted out so it could fake that it would work, but I have everything else working as expected and it is almost a finished product and do not wish to rewrite everything as the only problem I have is knowing how to select the next <span> when necessary.

PS: prefer no jQuery for this question.

Upvotes: 0

Views: 767

Answers (1)

Stem
Stem

Reputation: 56

Try using element.focus();

jsFiddle

Pure JS Version

Upvotes: 3

Related Questions