Why is $(document).ready not firing for me?

Viewed 84026

In a php file i have used include to include the following js.php file and prior to that i have included the jquery file.

<script type="text/javascript">

$(document).ready(function(){
     alert("hello");
});
</script>

But it doesn't work. Why? when I skip the $(document).ready function it works.

But i need jquery code inside. what is wrong?

14 Answers

Another cause that will silently fail, and all remaining callbacks never called:

$(document).ready(null);

So check if you have variables or syntax errors that return null. Like this one:

$(document).ready(function($){}(jQuery));

Notice that the function above is called instantly and undefined is returned.

In my case document.ready was not called because a html form was sent to server by Ajax request and only part of document was recived - and document ready is not called after ajax request.

In consequence some buttons which were on that part that was reloaded was not binded to events .click() atc.. anymore because these buttons were new and binding of these events was called during document ready only first time - not for AJAX.

Just had this crop up and it turned out to be a spelling mistake in the script tag:

<script type="text/javscript">

Note the missing 'a' in javascript. Changing to simply:

<script>

Fixed the problem.

If nothing above works another dirty trick is to wrap your function into to a SetTimeOut function without any time this simply queues the code to run once the current call stack is finished executing

     setTimeout(function(){
        FillOpenTranscriptionTasks();
    });

I've seen this problem caused by an iframe with a self-closing tag.

This is good:

<iframe src="http://..."></iframe>

This is not, and causes all JS on the page to fail silently:

<iframe src="http://..." />

instead of $( document ).ready( function() { ... } );

try

$( document ).ready( abc() );

function abc() { .... }

worked for me.i myself searched lot of places, but couldn't find a solution. Tried this out randomly and worked!!

I had such Problem, Just changed <script type="text/javascript"> to <script type="javascript"> and all problems gone!

Related