I’ve got a document with an HTML ordered list where some of the list items have hyperlinks to other items in the same list. Is there a way of getting hold of the displayed index that the browser has assigned to an item? I’ve seen various solutions based on counting the element’s position in the list but that depends on using integer indexes.
In the example below I’m using lowercase Roman numerals. I’ve hard coded “item iii” in the text of the link. The problem here is if I add an item at the beginning of the list, everything else gets moved down by one, and item iii becomes item iv. The link still links to the right place, but the description is wrong.
My real-world list is much longer and occasionally has items added or removed so I thought it would be nice if it could be “self-maintaining” 🙂
<ol type="i">
<li>Something</li>
<li>Something</li>
<li id="linkedItem">Something</li>
<li>Something</li>
<li>Something. See also <a href="#linkedItem">item iii</a>.</li>
</ol>