Strange situation:
I am building a menu bar using jQuery and CSS .
In my JavaScript file, I have an on-ready function, for example:
$(document).ready(function(e) { mark_active_menu(); }
and...
function mark_active_menu() { var elementWidth = $("nav li").width(); alert(elementWidth); }
For some reason, even before everything finishes loading the document, I get a message with the wrong width. Only when I release the message, the rest of the document is loaded, and I get the correct width, as it should be.
Why is my function called BEFORE THE ACHIEVEMENT OF ACHIEVEMENT OF DOCUMENT? Is there a way to load a function only after loading a specific element (example: nav element)?
Lior elrom
source share