Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: width() not working

Tags:

jquery

width

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

like image 753
Fuxi Avatar asked Jun 26 '26 00:06

Fuxi


1 Answers

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

like image 68
ehpc Avatar answered Jun 27 '26 15:06

ehpc