Jquery: create xpath of current text selection

Is there a way using jquery to get the XPath query of the current text selection?

Thank you for your help,

+3


source to share


2 answers


try this:

Updated It should now work:



var path = "/" + element.parents().map(function () {
    return this.tagName;
}).get().reverse().join("/");

path += "/" + element.prop("tagName") + "[" + (element.prevAll().length + 1) + "]";

      

http://jsfiddle.net/95PnT/5/

0


source


No, there is no built-in method for this using jQuery. There are however other javascript options, see here: How to calculate the XPath position of an element using Javascript?



0


source







All Articles