07-27-2023, 10:19 AM
For some reason `$("...").width()` is returning the wrong value immediately after document ready.
I'm see these values:
Immediately after document ready:
$(document).ready(function(){
$("li.active a").width() //returns 76 - incorrect
});
$(document).ready(function(){
$(window).load(function(){
$("li.active a").width() //returns 59 - the correct value
});
});
$(document).ready(function(){
setTimeout(function(){
$("li.active a").width() //returns 59 - the correct value
}, 100);
});
I'm getting the width of wordpress menu items and resizing them so that they always fit in my responsive design. There are no images or assets that should cause this change.
**Update**
See my comment below. Turns out there was an asset, an embedded font, that took a split second to load.
I'm see these values:
Immediately after document ready:
$(document).ready(function(){
$("li.active a").width() //returns 76 - incorrect
});
$(document).ready(function(){
$(window).load(function(){
$("li.active a").width() //returns 59 - the correct value
});
});
$(document).ready(function(){
setTimeout(function(){
$("li.active a").width() //returns 59 - the correct value
}, 100);
});
I'm getting the width of wordpress menu items and resizing them so that they always fit in my responsive design. There are no images or assets that should cause this change.
**Update**
See my comment below. Turns out there was an asset, an embedded font, that took a split second to load.