javascript - Attach script to jQuery ready method before jQuery is loaded -



javascript - Attach script to jQuery ready method before jQuery is loaded -

for example, bootstrap set jquery @ end of html, e.g. http://twitter.github.com/bootstrap/examples/starter-template.html

what if, want insert code block before loading of jquery script itself, e.g.

<div id="test1"></div> <div id="test2"></div> <script> $(document).ready(function() { $('#test1').html('test1'); // not work, workaround? code must set before.. }); </script> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script> $(document).ready(function() { $('#test2').html('test2'); // work }); </script>

test: http://jsfiddle.net/e5hkz/

i want both test1 & test2 displayed.

any idea?

if have set jquery code before line loads jquery itself, assign function document.ready.

window.document.ready = function() { $('#test1').html('test1'); };

when jquery has been loaded, reads variable , executes function @ dom ready.

note undocumented behavior , might not work reliably or in future jquery versions.

demo: http://jsfiddle.net/e5hkz/1/

javascript jquery html javascript-events twitter-bootstrap

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -