question
How to get the html index (counting in units of each html code string character) of a node?
ex
you have an html code
<div id="main_parag">Sample 789<!-- comment 23 -->29<script>let i = 47;</script>59<strong>69<span id="AA">Get_My_Index</span></strong></div>
how to get the html index of #AA
relative to (starting from) #main_parag
?
document.body.innerHTML = '<div id="main_parag">Sample 789<!-- comment 23 -->29<script>let i = 47;</script>59<strong>69<span id="AA">Get_My_Index</span></strong></div>';
let elt_outer = $('#main_parag')[0];
let elt_inner = $('#AA')[0];
let indHtml = get_IndHtml_of_eltInner_in_eltOuter(elt_inner, elt_outer); // expect 71
// Array.from(element.parentNode.children).indexOf(element)
// ^ this is not what I wanted, I want html index, not node index;
// plus that `AA` is not a direct child, but nested
comments
- (the element id may not be available in some cases)
- (I dont think Regex find is safe -- when there are multiple same strings?)