tags:

views:

22

answers:

3

hi all,

here's my simple code:

var msgbox = $("<div style='width:320px;height:200px;'></div>");
alert(msgbox.width());

the alert gives me zero - what's wrong? why isn't it 320?

thx

A: 

Try fetching element by getElementById in var then apply width function.

http://api.jquery.com/width/

org.life.java
+1  A: 

You need to first append the element to the DOM before trying to measure its size:

$('body').append(msgbox);
alert(msgbox.width());
Darin Dimitrov
+1  A: 

You should insert your div in the document first. Or use .css("width") instead.

ehpc