Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter hancoha

    (@hancoha)

    Thread Starter hancoha

    (@hancoha)

    I need help getting my jQuery script to work in WP. The script works fine outside of WP and I am not really sure why this is so.

    I’ve created a script that randomly changes backgrounds based on an array. Here is the code for the script:

    <script type="text/javascript">
    	$(document).ready(function() {
      		var randomImages = ['bg1','bg2','bg3','bg4','bg5'];
      		var rndNum = Math.floor(Math.random() * randomImages.length);
      		$("#rotate").css({ background: "url(assets/bg/" + randomImages[rndNum] + ".png) no-repeat top center" });
    	});
    </script>

    I know that it’s not convention to use the script tags in WP so instead, I’ve used the wp_enqueue_script to call my custom script. I’ve also changes out $() for jQuery() because I know that $() is default for the scriptalicious library. However, I still can’t get the script to work in WP. I’ve tried calling a simplified script to see if the location of my script worked. I used the following code

    window.onload = function(){ alert("welcome"); }

    This code worked fine. Can someone PLEASE help me? Much appreciated!

    within WordPress, instead of using $ use jQuery

    Then it will work fine

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom jQuery Script’ is closed to new replies.