javascript - document ready fires too early? -


it kind of theoretical question can't checked right away. problem possible reasons why jquery code doesn't work, loaded on page now. also, has right after page loaded , copy-paste script code source of loaded page console.

<body> <div id="id1">...</div> <div id="id2">some html code goes here... </div> <script>     jquery(document).ready(function() {             var el = jquery("#id1");             var var1 = el.width();             el.css({'margin-top':'10px','margin-bottom':'20px'});             jquery("#id2").css('margin-top', var1+'px');     }); </script> <div>and here... </div> </body> 

p.s. jquery library loaded. there no errors in chrome console. script in body tag.

p.p.s. can because of #id1 (contains ) loaded site document ready fired earlier? reason? other possible reasons?

unfortunately, hard check right away access page limited , takes several steps update other persons can't accessible right away. however, possible solution needed right away.

added id1 , id2 html code.

use window.onload used within element execute script once web page has loaded content.

jquery(window).load(function () {      var el = jquery("#id1");             var var1 = el.width();             el.css({'margin-top':'10px','margin-bottom':'20px'});             jquery("#id2").css('margin-top', var1+'px');  }); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -