alert(window.innerHeight); // inner window height
// change the background color to red
document.body.style.background = "red";
// change it back after 1 second
setTimeout(() => document.body.style.background = "", 1000);
// i.g control BOM
alert(location.href); // shows current URL
if(confirm("Go to Wikipedia")) {
location.href = "https://wikipedia.org"; // redirect the browser to another URL
}
Now the last selected element is available as $0
, the previously selected is $1
etc.
We can run commands on them. For instance, $0.style.background = 'red'
makes the selected list item red, like this:
That’s how to get a node from Elements in Console.
There’s also a road back. If there’s a variable referencing a DOM node, then we can use the command inspect(node) in Console to see it in the Elements pane.