Last active
December 20, 2015 11:59
-
-
Save petersooley/6127673 to your computer and use it in GitHub Desktop.
This is a jQuery plugin for determining the depth-first position of a child element.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // $('ul').depthPosition('li:nth-child(5)') | |
| (($) -> | |
| $.fn.depthPosition = (targetListItem) -> | |
| count = 1 | |
| for child in @children() | |
| if $(child).get(0) == $(targetListItem).get(0) | |
| return count | |
| else | |
| childDepths = $(child).depthPosition(targetListItem) | |
| count += childDepths | |
| return count | |
| )( jQuery ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment