I need to get the XPath of a DOM element to persist it so I can look for that element lather.
I've tried the getPathTo
method of this answer but when I call the method with a jQuery-created object like this...
getPathTo(jQuery('h3').first());
...I get this error:
Uncaught TypeError: Cannot read property 'childNodes' of undefined(…)
I've tried to replace parentNode
with parent()
, childNodes
with children()
, and tagName
with prop('tagName')
, but then I received undefined as the function result...
So, do you have a similar function to getPathTo
that works with jQuery?
getPathTo(jQuery('h3').first()[0])
– epascarello