How to get a reference to node in DOM tree in Google Chrome debugger console

Posted by .yahoo.co.jpaqwsykcj3aulh3h1k0cy6nzs3isj on Stack Overflow See other posts from Stack Overflow or by .yahoo.co.jpaqwsykcj3aulh3h1k0cy6nzs3isj
Published on 2010-02-22T08:16:47Z Indexed on 2010/04/11 13:23 UTC
Read the original article Hit count: 362

Filed under:
|
|

In the Google Chrome debugger, I often want to get a reference to a node in the DOM tree. I can click the "magnifying glass" button and then click the desired element in the browser window to select the corresponding node in the DOM tree displayed in the debugger. But how can I get a reference to that node in the console?

If the element has an id, document.getElementById works, but if there is no id, is there a better alternative to XPath or manual traversal of the DOM tree using children?

In case XPath is the best way, is there a better way than doing something like this:

var evaluator = new XPathEvaluator();
var result = evaluator.evaluate("//div", document.documentElement, null,
             XPathResult.FIRST_ORDERED_NODE_TYPE, null);

which is a pain to type out each time.

© Stack Overflow or respective owner

Related posts about dom

Related posts about google-chrome