mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
Add Reference The Selected Node as a chrome til
This commit is contained in:
20
chrome/reference-the-selected-node.md
Normal file
20
chrome/reference-the-selected-node.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Reference The Selected Node
|
||||
|
||||
In the Chrome dev tools, if you've selected (highlighted) a node in the DOM,
|
||||
you can reference that node from the console with `$0`. This is handy if you
|
||||
are debugging or exploring certain parts of a page and need to run commands
|
||||
against that node. For instance, if you were to select the `<html>` node in
|
||||
the DOM, you could then programmatically check the `lang` attribute from the
|
||||
console like so:
|
||||
|
||||
```
|
||||
> $0.lang
|
||||
// "en-US"
|
||||
```
|
||||
|
||||
If there is `jQuery` on the page and I've selected the node that contains
|
||||
all of the page's content, I can do something like the following:
|
||||
|
||||
```
|
||||
> $($0).html('<h1>Hello, World!</h1>')
|
||||
```
|
||||
Reference in New Issue
Block a user