Skip to content Skip to sidebar Skip to footer

Getselection().focusnode Inside A Specific Id Doesn't Work

I have code to bold/unbold scripts via Window.getSelection() I got it from this answer: Bold/unbold selected text using Window.getSelection() It really works without problems . But

Solution 1:

that window.getSelection().baseNode.parentNode.id When creating bold

The parent element of the text is obtained and find it Text Therefore, he did not reach the main father element who kissed him So replace the first line with this line and it works successfully Replace

window.getSelection().baseNode.parentNode.id != "editor"

To

window.getSelection().focusNode.parentElement.closest("#editor").id != "editor"

Post a Comment for "Getselection().focusnode Inside A Specific Id Doesn't Work"