owl
owl

Reputation: 4501

jQuery element width (Chrome bug)

If I reload the page with F5 width of element is 100. If I just click on internal link or press enter in browser-line width is 1847. In the Firefox, everything is fine. How to fix it?

$(document).ready(function() {
    console.log($("#element").outerWidth());
});

Thanks in advance.

Upvotes: 0

Views: 245

Answers (2)

Matt
Matt

Reputation: 75327

Try using $(window).load() instead of $(document).ready().

You'll likely have images/iframes etc that are being reloaded when doing F5, but used from cache normally.

The window load event waits for those images to load; the document ready event doesn't.

Upvotes: 1

Alex W
Alex W

Reputation: 38253

Try using $(window).resize() :

$( window ).resize(function() {
  console.log($("#element").outerWidth());
});

Upvotes: 1

Related Questions