Ajax
Ajax

Reputation: 80

Clear out previous value when new value displays

I've been creating this simple program to calculate screen width and height when resizing page. It gives the width and height of the page on load as the default but each time I resize it a new value gets displayed along with the previous one. I want only to display the new value. How can I do that?

Here's the HTML

<body onload="getSize()" onresize="getSize()">
<div id="wh"> 
<!-- Place height and width size here! --> 
</div>

Here's the JS


function getSize(){
    let w = window.innerWidth;
    let h = window.innerHeight;
    let displayThis = "Width is " + w + " and height is " + h;
    display.append(displayThis);
}

Upvotes: 0

Views: 50

Answers (1)

Eason Yu
Eason Yu

Reputation: 329

display.append(displayThis); means to add text after previous text, if you want to replace previous one,use this:

display.innerHtml = displayThis

this just replace element's inner html everytime, just keey the final one.

Upvotes: 2

Related Questions