Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is $(document).ready(); undefined?

I thought that I was doing everything right, however I keep getting this error. $(document).ready(); // undefined in the console. I imported my jquery script.

    <script src = "//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script >

        $(document).ready(function(){

            $("div#chat").hide();

        });

        function send_file(){

        }

        function remove_selected(){

        }

        function changeToFile(){

        }

        function chatToProfile(){

        }

        function changeToChat(){

        }
    </script>
like image 405
Dr.Knowitall Avatar asked Mar 06 '13 04:03

Dr.Knowitall


People also ask

What is the purpose of $( document ready ()?

$( document ).ready()A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.

Why document ready is deprecated?

Why document ready is deprecated? As of jQuery 3.0, only the first syntax is recommended; the other syntaxes still work but are deprecated. This is because the selection has no bearing on the behavior of the . ready() method, which is inefficient and can lead to incorrect assumptions about the method's behavior.

Can we define function in document ready?

The ready() method is used to make a function available after the document is loaded. Whatever code you write inside the $(document ). ready() method will run once the page DOM is ready to execute JavaScript code.

Where do I put jQuery document ready?

As a convention, placing the script element just before the closing body tag makes the script wait for the rest of the document to load before running. We also can make this process faster in jQuery by using the $(document). ready() method. The $(document).


1 Answers

If you're running this file locally (which I suspect you are...), this will attempt to find the referenced file on your local system, which will not be there.

To fix this, instead use this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
like image 83
Ryan Bigg Avatar answered Sep 27 '22 00:09

Ryan Bigg