views:

131

answers:

1

Is there anyway to return an XPath string of a DOM element in Javascript?

+2  A: 

There's not a unique XPath to a node, so you'll have to decide what's the most appropriate way of constructing a path. Use IDs where available? Numeral position in the document? Position relative to other elements?

See getPathTo() in this answer for one possible approach.

bobince
Hey, thanks that looks like a nice function. I made another question more appropriate and more context: http://stackoverflow.com/questions/2661918/javascript-crazy-idea-finding-a-node . In retrospect I should have edited this one... oops lol.
Louis