Javascript running from html but not php -
i've read similar question here, can't seem around in case, appreciate clarification. have page in php runs several instances of javascript work on cue on localhost. 1 particular instance of javascript (that makes arrow hide when scrolls beyond 10px) not run, when run same html version of same php page, arrow action works desired. why case? here code of page in jsfiddle (exactly same used respective sections in php page.)
to clarify have added bit of javascript in following manner @ end (after footer, before body end) of index.php file (along other blocks of javascript work desired respective targets):
<script type="text/javascript"> $(window).scroll(function () { if ($(this).scrolltop() > 10) document.getelementbyid('arr_downpoint').style.visibility = 'hidden'; else document.getelementbyid('arr_downpoint').style.visibility = 'visible'; }); </script>
i have added jquery follows (and works other instances on php page except arrow):
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
lastly, there no console errors. know why block of javascript isn't working php, works html (while other javascript instances work fine on both php , html), , how find out what's wrong?
resolution: found i'd erroneously added # while assigning arrowpoint id. that's why script couldn't arrowpoint, since <a>
had # part of name. sorry careless oversight, time may have taken consider.
if trying load page directly file (your page url start 'file://...') problem browser trying load jquery using same protocol (file instead of http) because didn't specify protocol external files (the src attribute starts '//', mean "use same protocol of current page"). can verify if reason behind problem, opening browser console looking errors like:
get file://code.jquery.com/jquery-1.11.3.min.js net::err_file_not_found file://code.jquery.com/jquery-migrate-1.2.1.min.js net::err_file_not_found uncaught referenceerror: $ not defined
to fix problem, should run html server (like apache php, did) or can write external scripts url including protocol (but can cause other problems if run page under https)
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
Comments
Post a Comment