Louis Louis - 1 year ago 155
Javascript Question

Javascript get XPath of a node

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download