style.width is not working for innerWidth

I am trying to insert a div dynamically with it's width equal to the page width using the window.innerWidth property.

It doesn't seem to work and the width is set to '0' automatically.

Thanks in advance.


<body onload="lb()"></body>


function lb()
var h=window.innerHeight

var w=window.innerWidth

                    alert("Width: "+w+"\n"+"Height: "+h);

        var x=document.createElement("div");"heder";;'150px';'#000000';'absolute';'0px';'0px';


Example fiddle :


You fogot to add "px" with width value

should be"px";

instead of;

As @Suman Bogati said you need to add the 'px'. Also your Fiddle was throwing an error executing the lb() function. I tweaked it in this fiddle to work. I just did a simple call to


Need Your Help

What is the proper way to enable character protrusion in xelatex?

xetex xelatex

I am using XeTeX 3.1415926-2.2-0.9997.4 (part of TeX Live 2010). One of its new features is character protrusion, and I would like to use it in my documents. The problem is that I cannot make it wo...

XHTML to another XHTML with XSLT

java xml xslt xhtml

I have two XHTML files and my task is to convert from one to another with XSLT (or any other method by Java Program). I searched but I didn't get any example for this, all are related for convertin...