javascript - chrome and ie console says top is undefined but safari and firefox have no error -


i stuck error. why ie 9 , chrome version 45 show error?

top undefined

am missing something? , of html layout affected in ie 9. , also, don't know if either font family or width of div in percentage getting error. please tell me, there solve problem?

var bodyscroll = 0; $(document).ready(function() {    bodyscroll = $(window).scrolltop();   currentp = 0;   currentp1 = 0;   currentp2 = 0;   $(window).scroll(function() {      scrtop = $(window).scrolltop();     bodyscroll < scrtop ? currentp = currentp - .8 : currentp = currentp + .8;     $(".maincontainer, .mobilebanner").css('background-position', "0  " + currentp + "px");     if (scrtop > $("#core-services .core-banner").position().top - 400) {       bodyscroll < scrtop ? currentp1 = currentp1 - .8 : currentp1 = currentp1 + .8;       $("#core-services .core-banner").css('background-position',  "0 " + currentp1 + "px");      }     if (scrtop > $(".core-contact").position().top - 400) {       bodyscroll < scrtop ? currentp2 = currentp2 - .8 : currentp2 = currentp2 + .8;       $(".core-contact").css('background-position', "0 " + currentp2 + "px");      }     bodyscroll = scrtop;   }); }); 

the following works me without error in chrome 43 (i'm test ie9) edit: it's working on ie9. suspect error not in code posted. need build minimal example reproduce error taking else out of page except relevant code, post js fiddle or stackoverflow native code thingy (like post), people can try in ie9 , confirm problem. it's normal debugging. you'll it. position().top should supported in ie9 , chrome.

edit: example of can go wrong in ie, check if have global variable same name id of html element. if can trigger "compatibility mode" bump ie down ie8 mode, did not support "article" html5 elements, wouldn't have "top" example.

var bodyscroll = 0;  $(document).ready(function() {      bodyscroll = $(window).scrolltop();    currentp = 0;    currentp1 = 0;    currentp2 = 0;    $(window).scroll(function() {        scrtop = $(window).scrolltop();      bodyscroll < scrtop ? currentp = currentp - .8 : currentp = currentp + .8;      $(".maincontainer, .mobilebanner").css('background-position', "0 " + currentp + "px");      if (scrtop > $("#core-services .core-banner").position().top - 400) {        bodyscroll < scrtop ? currentp1 = currentp1 - .8 : currentp1 = currentp1 + .8;        $("#core-services .core-banner").css('background-position', "0 " + currentp1 + "px");        }      if (scrtop > $(".core-contact").position().top - 400) {        bodyscroll < scrtop ? currentp2 = currentp2 - .8 : currentp2 = currentp2 + .8;        $(".core-contact").css('background-position', "0 " + currentp2 + "px");        }      bodyscroll = scrtop;    });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>  <section id="core-services">    <div class="core-banner">      <img src="images/core-services.jpg" class="img-responsive"/>    </div>  </section>


Comments