Skip to content
Advertisement

Javascript selected text highlighting prob

I have a html page with text content. On selecting any text and pressing the highlight button, I can change the style of the selected text to highlight the same. To implement this feature, i have written the following method.

JavaScript

This is working fine if you choose a text with no html tag, but when the text has any html tag in between, it is giving error

Failed to execute ‘surroundContents’ on ‘Range’: The Range has partially selected a non-Text node.

How to solve this problem. Is it possible to highlight the same separately for each part(divided by html tags)?

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement