1

With JavaScript, how can I get a string representation of a DOM node similar to what the Chrome and WebKit inspectors display?

tag#id.class1.class2

A real example would look something like these:

div#top-menu.feature.active
li.#callout.product

The desired strings might be query selectors, but I haven't found a native way of extracting them. These don't need to be absolutely precise CSS selectors either (no nth-child, etc.), just an identifying query string.

joemaller
  • 18,532
  • 7
  • 65
  • 81
  • 1
    This might be useful for you: http://stackoverflow.com/a/4588211/2991739 – mattias Dec 08 '16 at 20:35
  • @Matías I saw that, thank you. This wouldn't be difficult to write, but was hoping there was an attribute or built-in function to return the string. It's clearly already built into Chrome and Safari. – joemaller Dec 08 '16 at 21:01
  • 1
    As far as I know, there isn't a built-in function for this. You should implement it. – mattias Dec 08 '16 at 21:22

0 Answers0