Title: Custom jQuery Script
Last modified: August 19, 2016

---

# Custom jQuery Script

 *  [hancoha](https://wordpress.org/support/users/hancoha/)
 * (@hancoha)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/custom-jquery-script/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [hancoha](https://wordpress.org/support/users/hancoha/)
 * (@hancoha)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/custom-jquery-script/#post-1038933)
 *  Thread Starter [hancoha](https://wordpress.org/support/users/hancoha/)
 * (@hancoha)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/custom-jquery-script/#post-1038934)
 * 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!
 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/custom-jquery-script/#post-1039013)
 * 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.

## Tags

 * [background](https://wordpress.org/support/topic-tag/background/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [script](https://wordpress.org/support/topic-tag/script/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * Last activity: [17 years, 2 months ago](https://wordpress.org/support/topic/custom-jquery-script/#post-1039013)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
