previous lighthouse ticket #1357
by Michael Morris
I find myself needing to figure out an element's ordering among its siblings often enough to consider a universal method for it. Consider the following DOM
<ul><liid="first">Apple</li><liid="second">Orange</li><liid="third">Pear</li></ul>
The command $('first').index() would return 0, that element's position among its siblings. However, this function wouldn't consider tag types by design. Faced with a mixed tag type collection it still returns the index, but if the user wants nth-of-type they would have to use the proposed sibling function indexOfType.
<div><divid="first">Hello there</div><sectionid="second"> Sectioning</section><articleid="third"> articles</article><divid="fourth"> and so on.</div></div>
With the DOM above $('fourth').index() returns "3". $('fourth').indexOfType() returns "1" since it is the second div tag in the group.
Thoughts?
previous lighthouse ticket #1357
by Michael Morris
I find myself needing to figure out an element's ordering among its siblings often enough to consider a universal method for it. Consider the following DOM
The command $('first').index() would return 0, that element's position among its siblings. However, this function wouldn't consider tag types by design. Faced with a mixed tag type collection it still returns the index, but if the user wants nth-of-type they would have to use the proposed sibling function indexOfType.
With the DOM above$('fourth').index() returns "3". $ ('fourth').indexOfType() returns "1" since it is the second div tag in the group.
Thoughts?