Skip to content

Instantly share code, notes, and snippets.

@xarimanx
Created February 25, 2014 09:44
Show Gist options
  • Save xarimanx/9205946 to your computer and use it in GitHub Desktop.
Save xarimanx/9205946 to your computer and use it in GitHub Desktop.
get path
(($) ->
jQuery.fn.getPath = ->
throw "Requires one element." unless @length is 1
path = undefined
node = this
while node.length
realNode = node[0]
name = realNode.localName
break unless name
name = name.toLowerCase()
parent = node.parent()
siblings = parent.children(name)
name += ":eq(" + siblings.index(realNode) + ")" if siblings.length > 1
path = name + ((if path then ">" + path else ""))
node = parent
path
return
) jQuery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment