I'm trying to hightlight some part of a text in a html page having only the xPath (or css path) of the selected area, an anchorOffset and a focusOffset.
I know how to manage this using the selection() method from user input, but i'm having serious difficulties trying to reproduce the same mechanism in an automathic way without the selection but only with these infos
Example: (imagine I have many others like this)
Xpath : heyThere[1]
anchorOffset : 3
focusOffset : 45
My goal is something like this
(see pic) http://oi57.tinypic.com/68aebo.jpg
can anybody give me an hint for this task?
Thanks a lot!
I don't see how a relative path like
heyThere[1]
would select anything in an HTML document as the root element name ishtml
and notheyThere
. As for styling a certain part, assuming you have a path leading to a text node and the offsets are inside that text node, you can create a range using the W3C DOM Level 2 Rang API, create aspan
with a certain CSS class as a wrapper and that way the text can be highlighted. Note that support for that DOM API is not available in older IE versions, I think only Edge on Windows 10 supportsdocument.evaluate
with XPath and I am not sure about the range support.I looked up the IE support, the range API is supported since IE 9 so only the XPath based access does not work, an example for IE using CSS based node selection is