Louis Louis - 2 months ago 6x
Javascript Question

Javascript get XPath of a node

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


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.