Is there a way, using jquery to get an XPath query of the current text selection?
Thanks for your help,
Is there a way, using jquery to get an XPath query of the current text selection?
Thanks for your help,
try this:
Updated It should work now:
var path = "/" + element.parents().map(function () {
return this.tagName;
}).get().reverse().join("/");
path += "/" + element.prop("tagName") + "[" + (element.prevAll().length + 1) + "]";
No, there is no built-in method to do this using jQuery. There are, however, other javascript options, see here: How to calculate the XPath position of an element using Javascript?