How to get absolute DOM path of html element

12,514

You could use querySelector(), but it doesn't have great support...

var elem = document.querySelector('html body div table tbody tr td table tbody tr td table tbody tr td table tbody tr td form table tbody tr td');

Otherwise just use a library that allows you to use CSS selectors, such as jQuery.

var $elem = $('html body div table tbody tr td table tbody tr td table tbody tr td table tbody tr td form table tbody tr td');

By the way, selecting like this is horrible for performance. Absolutely terrible. Have a read up on CSS selectors to learn why.

Share:
12,514
Rpk_74
Author by

Rpk_74

Updated on June 04, 2022

Comments

  • Rpk_74
    Rpk_74 almost 2 years

    I'm having problems with html DOM.

    How do I get the value from this path:

    html body div table tbody tr td table tbody tr td table tbody tr td table tbody tr td form table tbody tr td

    I can only find stuff like getElementbyID/tag/name/class etc.

    How do I get the absolute DOM 'path' of the td element (let's say the 3rd cell of the second row in that table)? I've been looking everywhere but cannot find a simple answer without ID/Class etc involved.