jquery - Is inline/block Javascript executed before document-ready? -
assuming 1 has inline javascript code in html document (the body example), piece of javascript executed before jquery document-ready code?
for example, following safe?
... <body> <script type="text/javascript"> var myvar = 2; </script> ... </body> ... $(document).ready(function() { alert('my var = ' + myvar); }
if not, how can make safe knowing myvar
defined in inline/block code?
yes, above code safe. inline js executed encountered while document being parsed top bottom. document ready handler executed when document ready (obviously), , won't ready until whole document has been parsed including inline scripts.
note don't need document ready handler if include code wraps last thing in document body, because @ point not other inline js have executed of document elements have been added dom , accessible js.
Comments
Post a Comment