2

I have this in my HTML (not dynamically added or anything like that):

<div id="TEST" style="width:600px; height:300px;"></div>

and when I do this: alert(jQuery("#TEST").width());

... it alerts 1280 in IE! It's alerting 600 in Chrome - what could be messing with this?

These are the only styles applied:

enter image description here

EDIT I've even tried this and still 1280...

jQuery("#TEST").width(600);
alert(jQuery("#TEST").width());

EDIT AGAIN

Okay, I have looked inside the jQuery implementation and it is because it is returning true from this if statement:

if ("scrollTo" in elem && elem.document) ? // does it walk and quack like a window?

WHY does my div "walk and quack like a window"?

Fiona - myaccessible.website
  • 14,481
  • 16
  • 82
  • 117

2 Answers2

4

Would need to see the rendered component to see where the styles are coming from, but you should read about outerWidth.

http://api.jquery.com/outerWidth/

Edit: After seeing your updated screenshot, you should make the element block level or inline-block level. Setting the width of an inline element will not provide desired results because it changes based on the element's positioning.

More about inline vs. block elements here: http://www.w3.org/TR/html401/struct/global.html#h-7.5.3

PS. I know a div is a block element, is something in your code forcing it into an inline?

Terry
  • 14,099
  • 9
  • 56
  • 84
1

Maybe get the CSS width?

alert($("#TEST").css("width"));
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164
Michael Hommé
  • 1,696
  • 1
  • 14
  • 18