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?
The method expects a DOM node and you are giving it a jQuery object
getPathTo(jQuery('h3').first()[0])
or
getPathTo(jQuery('h3').first().get(0))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With