lewashby Posted July 25, 2016 Share Posted July 25, 2016 My browser is loading the webpage just fine and there are no errors reported in /var/log/apache/error.log but I can't get this simple jQuery alert to show up after refreshing the browser. Do you see anything wrong with me code? Thanks. HTML <-index.html <!DOCTYPE html> <html> <head> <title>jQuery Content Slider</title> <link rel='stylesheet' href='css/style.css'> <script src='jquery-3.0.0.min.js'></script> <script src='js/script.js'></script> </head> jQuery <- js/script.js $(document).ready(function() { alert('Doc is ready'); }); Quote Link to comment https://forums.phpfreaks.com/topic/301579-jquery-documentready-not-working/ Share on other sites More sharing options...
Jacques1 Posted July 25, 2016 Share Posted July 25, 2016 JavaScript code is executed by the browser, not the server. So what do the developer tools of your browser say? The Network tab shows HTTP errors (404 etc.), the JavaScript console reports JavaScript errors. Quote Link to comment https://forums.phpfreaks.com/topic/301579-jquery-documentready-not-working/#findComment-1534969 Share on other sites More sharing options...
lewashby Posted July 25, 2016 Author Share Posted July 25, 2016 I see the 404 error and I also see that is says '$' is not defined. I'm following along with a web dev course on udemy.com and my pages look identical to his so I don't understand what the problem is. I thought $(document).ready() was valid syntax for a .js file? Quote Link to comment https://forums.phpfreaks.com/topic/301579-jquery-documentready-not-working/#findComment-1534972 Share on other sites More sharing options...
Solution Jacques1 Posted July 25, 2016 Solution Share Posted July 25, 2016 A 404 error means that a file could not be found. So either your jquery-3.0.0.min.js script doesn't exist on the server at all, or you've put it into the wrong location. To match the URL, it must be located next to the index.html file: src="jquery-3.0.0.min.js" If you want it to be in your "js" folder instead, you must adjust the URL: src="js/jquery-3.0.0.min.js" Quote Link to comment https://forums.phpfreaks.com/topic/301579-jquery-documentready-not-working/#findComment-1534973 Share on other sites More sharing options...
lewashby Posted July 25, 2016 Author Share Posted July 25, 2016 While following along the lessons I forgot I had moved all the files in the previous working lesson into a sub directory 'old' including the jquery file. I feel stupid, and it won't be the last time. Thanks for your help Jacques1. It is solved. Quote Link to comment https://forums.phpfreaks.com/topic/301579-jquery-documentready-not-working/#findComment-1534974 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.