Charlie
Charlie

Reputation: 23818

How do I update a variable logged in to Chrome console

Let say I need to track the window size and log the output. I add an event listner and use

console.log(window.innerWidth)

However this adds a new line to the console every time the window is resized.

What I need is to show the innerWidth in a single line in the console which updates it everytime the window is resized.

Upvotes: 1

Views: 656

Answers (2)

Kayce Basques
Kayce Basques

Reputation: 25947

As Garbee said, you can't achieve that functionality in the standard Console. You could alternatively use a watch variable to keep track of window.innerWidth. Unfortunately you need to manually reload it.

using watch variable to keep track of window.innerWidth

Upvotes: 2

Garbee
Garbee

Reputation: 10991

You can't have a line that updates. The console lines are appended to, not capable of being overwritten.

You need to build a custom UX to handle this need for your app as an overlay. Or you can use Device Mode as "Responsive" to let you resize freely and see the update width/height within that window.

Upvotes: 3

Related Questions