JQuery ready function doesn't work in WordPress

I am using jQuery in WordPress (@HOME page) and the finished function does not work for me. I have an index.php that includes a (php) header, footer and sidebar. I checked this code:

<script type="text/javascript" src="path_to_jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { alert ("test text"); }); </script> 

A warning (with the text "test text" ) does not appear immediately! It appears only after loading the sidebar. This means that while I see the index page (the sidebar is not loaded yet), I have to wait a few seconds until the sidebar finishes loading, and only then will jQuery code be executed: a warning appears. So the finished function just doesn't work. Can someone tell me why and how can I solve this problem? Thanks.

+7
wordpress
source share
3 answers

in a WordPress environment, use this:

 jQuery(function($){ // now you can use jQuery code here with $ shortcut formatting // this executes immediately - before the page is finished loading }); jQuery(document).ready(function($){ // now you can use jQuery code here with $ shortcut formatting // this will execute after the document is fully loaded // anything that interacts with your html should go here }); 
+44
source share

A warning appears after loading the sidebar, because ready () must be executed AFTER the completion of the entire download page.

+2
source share

A warning (with the text "test text") does not immediately appear! It appears only after loading my site.

This is definitely the advantage of using ready . When you want it to pop up right away, just do

 <script type="text/javascript"> alert ("test text"); </script> 
+1
source share

All Articles