I want to retrieve the DOM path of a random element in a website (like Firebug or this Greasemonkey userscript ) when I click on this element. No problem for this part, I return a string containing the path.
The only drawback being I don't need a full path such as
html > body > div #mainPanel > table #pageBody > tbody > tr > td
Just this : #pageBody > tbody > tr > td
would be enough to retrieve the element using jQuery or Dojo.
I thought of using a Regexp to remove all that's before the last id, this should not be an issue.
As for class, I'm not sure I can do the same, because it could be useful to see if other elements match the pattern. For example, in my site .DiscreetList > li
matches 6 nodes. How can I retrieve the good one?
Are there other possibilities for shortening besides the class and id trick? (for use in jQuery/Dojo or equivalent)
Edit : After the remarks, I found this snippet (© Greg's code)
Now, the problem with index is fixed, and I decided, based on the comments, to shorten by the id, safe way to go :)
Thanks for your answers.