How to get the parent element in an HTML string at a given offset?

New Question

I am looking for a way in Javascript to get the parent element of a given position in an HTML string (e.g. document.innerHTML or document.body.innerHTML).

Simple example:

<p>I really <em>like <a href="...">stackoverflow</a></em> a lot.</p> ^...........^ Offset 35 to 48

Given offset 35 (to 48), the function should return the node object of the "a" element. I am wondering whether this is possible at all and, if it is, what would be a good approach to solve this.

Thanks in advance for your efforts!


Old Question

Is there a way to highlight text at a given offset in an HTML document with Firefox?

I have a list of offsets and lengths of strings to highlight. I suppose I need to find out the parent element of the text node at the given offset, is this right?

I don't think it should be a problem for me to add the highlighting once I've got the right parent node, since this is simply DOM manipulation.

Do you have any ideas or hints?

<strong>Clarification:</strong> The offsets are relative to the contents of the body tag. Thanks @ Jonathan for pointing this out.

Thank you very much.


check out the source of Search and Highlight With Javascript, it may be give you a good place to start.


  • What is the use/purpose of MQTT QoS?
  • MVC4 App Targets .NET 4.0 but seems to Require .NET 4.5 to Run
  • Autofill a column with month name depending on the date in another column - Excel VBA
  • Indexing through Android string resources
  • OpenCL kernel not vectorized
  • Excel 2007: Format of email address from Outlook 2007
  • Making Cross Site Asynchronous HTTP Post from GWT Client
  • Connect Node.js with Oracle on Windows platform
  • How to implement limit with Nhibernate and Sybase
  • HALF_PTR Windows data type
  • div fade-in when window is scrolled a certain distance from the top
  • How to define an array of floats in Shader properties?
  • Regex for Specific Tag
  • A new chart every sheet
  • How can we prepend rows to a react native list-view?
  • Simple linked list-C
  • Is it possible to open regedit and navigate to straight to a specific key using process.start?
  • CakePHP ACL tutorial initDB function warnings
  • What's the purpose of QString?
  • Jackson Parser: ignore deserializing for type mismatch
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • R: gsub and capture
  • AT Commands to Send SMS not working in Windows 8.1
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Benchmarking RAM performance - UWP and C#
  • How do I configure my settings file to work with unit tests?
  • Is it possible to post an object from jquery to bottle.py?
  • Django query for large number of relationships
  • reshape alternating columns in less time and using less memory
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can i traverse a binary tree from right to left in java?
  • How can I use `wmic` in a Windows PE script?
  • Net Present Value in Excel for Grouped Recurring CF
  • How to push additional view controllers onto NavigationController but keep the TabBar?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?