Title: Getting Javascript to kick in
Last modified: August 24, 2016

---

# Getting Javascript to kick in

 *  [Carolyn](https://wordpress.org/support/users/carobee/)
 * (@carobee)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/)
 * Hi There,
 * Using Twenty Thirteen child theme – adding a drop-down navigation menu which 
   uses javascript.
 * I’ve got everything in place and I’ve read the codex and followed it to the letter
   but still no movement.
 * I’ve put the js file in my child theme folder – added a link to the header.php–
   can’t work out where I’m going wrong. Any help would be amazing!
 * Thank you

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

 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/#post-6107413)
 * Are you able to post a link to the site?
 *  Thread Starter [Carolyn](https://wordpress.org/support/users/carobee/)
 * (@carobee)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/#post-6107415)
 * Hi Jose,
 * It’s at [http://www.inverrestaurant.co.uk/test](http://www.inverrestaurant.co.uk/test)
 * The javascript I’m adding is from [http://tympanus.net/codrops/2012/10/04/custom-drop-down-list-styling/](http://tympanus.net/codrops/2012/10/04/custom-drop-down-list-styling/)–
   example 3.
 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/#post-6107420)
 * Where is the code residing and how are you loading it?
 *  Thread Starter [Carolyn](https://wordpress.org/support/users/carobee/)
 * (@carobee)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/#post-6107441)
 * The code is in a document called menu.js in the themes folder. I’m calling it
   in the header.php with this html……
 * <script type=”text/javascript” src=”<?php bloginfo(‘template_url’); ?>/inver/
   menu.js”></script>
 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/#post-6107464)
 * Ah, makes a little more sense now!
 * What you actually want to do is have the file in the child theme folder rather
   than the parent theme. That way if the theme gets updated you won’t lose that
   file. 😉
 * From there rather than hardcoding the `script`, you enqueue it. That way you 
   can declare any dependencies if there are any.
 * In the `functions.php` file you would add something like:
 *     ```
       add_action( 'wp_enqueue_scripts', 'my_child_scripts' );
       function my_child_scripts(){
           wp_enqueue_script( 'menu-js', get_stylesheet_directory_uri() . '/menu.js', array( 'jquery' ), '', true );
       }
       ```
   
 * Or something along those lines. A little more information about enqueuing styles
   and scripts can be found on the codex as well: [https://codex.wordpress.org/Function_Reference/wp_enqueue_script](https://codex.wordpress.org/Function_Reference/wp_enqueue_script)
 * ps. I took a quick look and the JavaScript file appears to be empty. It loaded
   fine.
 *  Thread Starter [Carolyn](https://wordpress.org/support/users/carobee/)
 * (@carobee)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/#post-6107465)
 * Hi Jose,
 * Thanks so much for taking a look at this..I really appreciate you help.
 * I just checked the menu.js file on the server and there is code in there, I’m
   just wondering if the file is headed up correctly – I’ve copy and pasted exactly
   what is there…..
 * _[ Moderator note: Code fixed, please wrap code in [backticks or use the code button](http://codex.wordpress.org/Forum_Welcome#Posting_Code).]_
 *     ```
       //...
   
       	obj.dd.on('click', function(event){
       		$(this).toggleClass('active');
       		return false;
       	});
   
       	//...
   
       	$(function() {
   
       		var dd = new DropDown( $('#dd') );
   
       		$(document).click(function() {
       			// all dropdowns
       			$('.wrapper-dropdown-1').removeClass('active');
       		});
   
       	});
   
           function DropDown(el) {
           this.dd = el;
           this.opts = this.dd.find('ul.dropdown > li');
           this.val = [];
           this.index = [];
           this.initEvents();
       }
       DropDown.prototype = {
           initEvents : function() {
               var obj = this;
   
               obj.dd.on('click', function(event){
                   $(this).toggleClass('active');
                   event.stopPropagation();
               });
   
               obj.opts.children('label').on('click',function(event){
                   var opt = $(this).parent(),
                       chbox = opt.children('input'),
                       val = chbox.val(),
                       idx = opt.index();
   
                   ($.inArray(val, obj.val) !== -1) ? obj.val.splice( $.inArray(val, obj.val), 1 ) : obj.val.push( val );
                   ($.inArray(idx, obj.index) !== -1) ? obj.index.splice( $.inArray(idx, obj.index), 1 ) : obj.index.push( idx );
               });
           },
           getValue : function() {
               return this.val;
           },
           getIndex : function() {
               return this.index;
           }
       }
       ```
   
 *  Thread Starter [Carolyn](https://wordpress.org/support/users/carobee/)
 * (@carobee)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/#post-6107466)
 * ..I’ve put the menu.js in the child theme folder 🙂 and added this to the functions.
   php
 * _[ Moderator note: Code fixed, please wrap code in [backticks or use the code button](http://codex.wordpress.org/Forum_Welcome#Posting_Code).]_
 *     ```
       add_action( 'wp_enqueue_scripts', 'my_child_scripts' );
       function my_child_scripts(){
           wp_enqueue_script( 'menu-js', get_stylesheet_directory_uri() . '/menu.js', array( 'jquery' ), '', true );
       }
       ```
   
 *  Thread Starter [Carolyn](https://wordpress.org/support/users/carobee/)
 * (@carobee)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/#post-6107468)
 * Thanks a lot Mod 🙂 Sorry newbie here x
 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/#post-6107478)
 * > Thanks a lot Mod 🙂 Sorry newbie here x
 * It happens. 😉
 * Great! Took a second look and the content is there, being loaded from the child
   theme! There are a few errors, that are being thrown if you open your developer
   tools console.
 * Both of the ones that matter are the JavaScript related ones. Both of which are`
   Uncaught Reference` errors. What this means is that two things are not defined
   in your scripts. The first one is `news()` and the second one is `obj`. Unfortunately
   these forums are not meant for JavaScript issues but I hope that does give you
   some information and steer you in the right direction a little better. 🙂
 *  Thread Starter [Carolyn](https://wordpress.org/support/users/carobee/)
 * (@carobee)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/#post-6107479)
 * I don’t really know what it means but now I know where to look I might have a
   chance of solving it.
 * Thanks very much Jose! You’ve been great. 🙂

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

The topic ‘Getting Javascript to kick in’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 2 participants
 * Last reply from: [Carolyn](https://wordpress.org/support/users/carobee/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/getting-javascript-to-kick-in/#post-6107479)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
