1

Can Chrome's last inspected elements be access with javascript?

Background, trying to integrate this into a Debug.js file to be called onclick. https://stackoverflow.com/a/12596540/511438

I am trying to integrate the function provided above to execute on a clickable element.

Here is my attempt which results in undefined even though i have inspected elements prior to executing this.

$(document).on('click', "#debugelements", 
    function () { CompareElements(window.$0, window.$1); });

and

function CompareElements(a, b)
{
... as per the answer above.
}

i suspect $0 is inaccessable to javascript. Is there a way to do this in javascript without pasting the whole function into the Chrome console?

Community
  • 1
  • 1
Valamas
  • 24,169
  • 25
  • 107
  • 177

1 Answers1

3

I'm afraid that only Chrome Extensions have access to these variables. There is a sample extension that makes use of $0, it's called 'Chrome Query' and is available on samples page. I took it's code, modified a little and ended up with this extension. The code is available on github. I'm not sure if it's extra useful in current form, but there is a lot of space for improvement. Table instead of a tree should be more readable, I'll try to make it happen next week.

screenshot from CSS Diff extension

Konrad Dzwinel
  • 36,825
  • 12
  • 98
  • 105