Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force DOM element in "inspected mode"

In Chrome, if one right-clicks a DOM element and selects "inspect element", then one is brought to the "Elements" tab of the debugger. In addition, the JavaScript variable $0 becomes populated with the "inspected" DOM element.

Given a DOM element, is there a way to have JavaScript force the browser to "inspect" it, so that the browser fills in the value for $0 natively, without doing the assignment ourselves?

like image 557
Randomblue Avatar asked Aug 26 '12 18:08

Randomblue


1 Answers

As written in the documentation, the Chrome Web Developer supports Firebug's Command Line API. And one of the methods present there is inspect which does what you want.

Unfortunately, that is a Command Line API, which means that it's only valid in the console, at the command line, not from in-page scripts. There's no way to control the web developer tool from an in-page script, other than through the Console API which provides mostly logging facilities.

like image 72
Sergiu Dumitriu Avatar answered Oct 29 '22 15:10

Sergiu Dumitriu