Skip to main content
added 76 characters in body
Source Link
TheGeekZn
  • 4k
  • 11
  • 58
  • 92

Offset Index of childChild DOM element within parentParent

I'm looking for a pure JS way of finding the offset of a child within it's parent.

Given the below sample:

<div> A <br> short space elapsed, <b>and</b> up into this noiselessness came Ahab alone from his cabin. <span>Taking a few turns on the quarter-deck, he paused to gaze over the side</span> </div> 

I would get 3 children, a br, b, and span. Each would need to have an offset to the start of the div - So the index of how many characters into the div the start of the tag is.
So the br would have an offset of 2.

My initial idea was to get all the children of the div, then somehow from that be able to easily get an index.

Offset of child within parent

I'm looking for a pure JS way of finding the offset of a child within it's parent.

Given the below sample:

<div> A <br> short space elapsed, <b>and</b> up into this noiselessness came Ahab alone from his cabin. <span>Taking a few turns on the quarter-deck, he paused to gaze over the side</span> </div> 

I would get 3 children, a br, b, and span. Each would need to have an offset to the start of the div.
So the br would have an offset of 2.

My initial idea was to get all the children of the div, then somehow from that be able to easily get an index.

Index of Child DOM element within Parent

I'm looking for a pure JS way of finding the offset of a child within it's parent.

Given the below sample:

<div> A <br> short space elapsed, <b>and</b> up into this noiselessness came Ahab alone from his cabin. <span>Taking a few turns on the quarter-deck, he paused to gaze over the side</span> </div> 

I would get 3 children, a br, b, and span. Each would need to have an offset to the start of the div - So the index of how many characters into the div the start of the tag is.
So the br would have an offset of 2.

My initial idea was to get all the children of the div, then somehow from that be able to easily get an index.

added 2 characters in body
Source Link
TheGeekZn
  • 4k
  • 11
  • 58
  • 92

I'm looking for a pure JS way of finding the offset of a child within it's parent.

Given the below sample:

<div> A <br> short space elapsed, <b>and</b> up into this noiselessness came Ahab alone from his cabin. <span>Taking a few turns on the quarter-deck, he paused to gaze over the side</span> </div> 

Looking at the above HTML, I'd like toI would get the offset of all the3 children. For example, thea <br>br, b, and span. Each would need to have an offset to the start of 2 (Because the div is.
So the parent I'm looking in)br would have an offset of 2.

My initial idea was to get all the children of the div, then somehow from that be able to easily get an index.

I'm looking for a pure JS way of finding the offset of a child within it's parent.

<div> A <br> short space elapsed, <b>and</b> up into this noiselessness came Ahab alone from his cabin. <span>Taking a few turns on the quarter-deck, he paused to gaze over the side</span> </div> 

Looking at the above HTML, I'd like to get the offset of all the children. For example, the <br> would have an offset of 2 (Because the div is the parent I'm looking in).

My initial idea was to get all the children of the div, then somehow from that be able to easily get an index.

I'm looking for a pure JS way of finding the offset of a child within it's parent.

Given the below sample:

<div> A <br> short space elapsed, <b>and</b> up into this noiselessness came Ahab alone from his cabin. <span>Taking a few turns on the quarter-deck, he paused to gaze over the side</span> </div> 

I would get 3 children, a br, b, and span. Each would need to have an offset to the start of the div.
So the br would have an offset of 2.

My initial idea was to get all the children of the div, then somehow from that be able to easily get an index.

Source Link
TheGeekZn
  • 4k
  • 11
  • 58
  • 92

Offset of child within parent

I'm looking for a pure JS way of finding the offset of a child within it's parent.

<div> A <br> short space elapsed, <b>and</b> up into this noiselessness came Ahab alone from his cabin. <span>Taking a few turns on the quarter-deck, he paused to gaze over the side</span> </div> 

Looking at the above HTML, I'd like to get the offset of all the children. For example, the <br> would have an offset of 2 (Because the div is the parent I'm looking in).

My initial idea was to get all the children of the div, then somehow from that be able to easily get an index.