Jump to content

jQuery $(document).ready() not working


lewashby
Go to solution Solved by Jacques1,

Recommended Posts

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');
}); 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Solution

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"
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.