I'm trying to use JavaScript to change the width of a div, but something's wrong with one part of my code. I think it's this part:
document.getElementById("div").style["width"] = width+"px";
I'm not sure what's wrong with it, so if you know, please let me know. Thanks.
<script>
function adapt (percentage) {
var width = percentage/100;
var width = window.innerWidth*width;
document.getElementById("div").style["width"] = width+"px";
}
adapt(80);
</script>
<style>
div {
border: 1px solid black;
}
</style>
<div id = 'div'> </div>
headsection of the page?