Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

range.extractContents() sometimes only pick innerHTML only the whole document fragment if only one character selected #451

Open
lishiying410 opened this issue Aug 1, 2018 · 0 comments

Comments

@lishiying410
Copy link

I have some text for user to select, like:

    <span onmouseup="top.onMouseUpEssence('534','');" name="534">h</span>
    <span onmouseup="top.onMouseUpEssence('534','');" name="534">e</span>
    <span onmouseup="top.onMouseUpEssence('534','');" name="534">r</span>
    <span onmouseup="top.onMouseUpEssence('534','');" name="534">e</span>

When user selects character 'e', some times the extractContents method only returns innerHTML 'e', not<span onmouseup="top.onMouseUpEssence('534','');" name="534">e</span>

Here is my code:

var selection = window.getSelection();
var range = selection.getRangeAt(0);
var container = document.createElement("span");
var selectionContents = range.extractContents();
container.appendChild(selectionContents);

Does any one know why? Thanks. I tested Firefox, it's sometimes working, for chrome, it's not working at all when only one character is selected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant