I'm quite new to Javascript but thought that I should challenge myself to use it to solve an old problem of mine.
I'm trying to set the height of a div to the same as the width of it. Example:
The width is set to 50% and the screen is 1000px wide, the element will be 500px wide. I want the height to be the same; 500px.
I tried to achieve this using this Javascript code:
var layer=document.getElementById('layer');
var layer_width=layer.width();
layer.style.height=layer_width;
The width of 'layer' has been set to 50% in CSS. The height is unaffected however. What am I doing wrong