Title: Javascript Not Working in Child Theme
Last modified: August 21, 2016

---

# Javascript Not Working in Child Theme

 *  [mcography](https://wordpress.org/support/users/mcography/)
 * (@mcography)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/)
 * I am working on a child theme of Twenty Thirteen. I want to make a slide down
   about page (something like [the one seen here](http://terribleminds.com/)), but
   I can’t get the javascript to work.
 * I put this before the end of <head> in header.php:
 *     ```
       <script>
        $(document).ready(function(){
        $("toggle").click(function(){
         $("abouttoggle").slideToggle();
         });
        });
       </script>
       ```
   
 * And this in the body:
 *     ```
       <div id="abouttoggle">
        <div id="abouttoggle_inner">
          <h1>This is the About Page.</h1>
           <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
         </div>
       </div>
       ```
   
 * But when I click the button, it doesn’t do anything. What am I doing wrong?

Viewing 15 replies - 1 through 15 (of 32 total)

1 [2](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/page/2/?output_format=md)

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202471)
 * Doesn’t look like you’re enqueing the JavaScript or using no-conflict wrappers.
 * See:
    – [http://codex.wordpress.org/Function_Reference/wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script)–
   [http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers](http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers)
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202474)
 * Also you’re trying to select these elements:
 *     ```
       <toggle>
       ```
   
 * and
 *     ```
       <abouttoggle>
       ```
   
 * Do you see what I mean here?
 * See jQuery selectors: [http://api.jquery.com/category/selectors/](http://api.jquery.com/category/selectors/)
 *  Thread Starter [mcography](https://wordpress.org/support/users/mcography/)
 * (@mcography)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202480)
 * I did try to figure out wp_enqueue_script but it didn’t seem to work, and I found
   it confusing. I will look at it again.
 * As far as your second comment, yes I understand. It should be “#abouttoggle” 
   not “abouttoggle” right? I fixed that, but it’s still not working. Even if I’m
   not putting the script in the recommended place (using wp_enqueue_script), shouldn’t
   it still work if it’s in the head of the document?
 * Thanks for your help, by the way.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202484)
 * Can you link the page in question? I can’t answer whether it should work alone
   otherwise.
 *  Thread Starter [mcography](https://wordpress.org/support/users/mcography/)
 * (@mcography)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202487)
 * [This is the site](http://cubackpack.org/dev) I’m working on. Thanks.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202490)
 * Try using chrome’s developer toolbar for JavaScript debugging: [https://developers.google.com/chrome-developer-tools/](https://developers.google.com/chrome-developer-tools/)
 * Right click on the page (anywhere applicable) and select “Inspect element”. Then
   go to the “Console” panel.
 * Do you see [the error](http://snag.gy/8uyID.jpg)?
 * First resolve that error. It’s because you’re not using a no-conflict wrapper.
 *  Thread Starter [mcography](https://wordpress.org/support/users/mcography/)
 * (@mcography)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202495)
 * According to the instructions about no conflict wrappers [here](http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers),
   I changed the script to
 *     ```
       <script>
        jQuery(document).ready(function(){
        $("toggle").click(function(){
         $("#abouttoggle").slideToggle();
         });
        });
       </script>
       ```
   
 *  But it’s still giving me an error saying the jQuery is not defined. How do I
   fix that?
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202498)
 * You can’t use the dollar like that unless you pass it through your wrapper’s 
   parameter, see the third example:
    [http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers](http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers)
 *  Thread Starter [mcography](https://wordpress.org/support/users/mcography/)
 * (@mcography)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202499)
 * I thought the third example meant that you could use the dollar sign within the“
   jQuery(document).ready(function(){” wrapper. However, I changed it to
 *     ```
       <script>
        jQuery(document).ready(function(){
         jQuery("toggle").click(function(){
          jQuery("#abouttoggle").slideToggle();
          });
        });
       </script>
       ```
   
 * and it’s still not working. Any ideas?
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202501)
 * Converting this jQuery
 *     ```
       jQuery(document).ready(function(){
        $("toggle").click(function(){
         $("#abouttoggle").slideToggle();
         });
        });
       ```
   
 * To how the third example explains would result in this:
 *     ```
       jQuery(document).ready(function($){
        $("toggle").click(function(){
         $("#abouttoggle").slideToggle();
         });
        });
       ```
   
 * Now it’s saying jQuery is not defined because you’re trying to use jQuery before
   the jQuery library has been called. It’ll be easier if you enqueue your JavaScript.
 * If you want to see how easy enqueing JavaScript can be look at **stage 2**, step
   2 on this tutorial I made for some jQuery that needed enqueing for another theme:
   [http://wordpress.org/support/topic/put-test-inside-images-on-home-page](http://wordpress.org/support/topic/put-test-inside-images-on-home-page)
 * **Stage 2**, step 2 is the part where you enqueue the JavaScript. You put the
   JavaScript in a file and enqueue it.
 *  Thread Starter [mcography](https://wordpress.org/support/users/mcography/)
 * (@mcography)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202510)
 * I followed your instructions for Stage 2 and enqueued the script, but it’s still
   not working.
 * I put this in functions.php:
 *     ```
       <?php
       	function toggleAbout() {
       		wp_enqueue_script( 'toggle-about', get_stylesheet_directory_uri() . '/../../js/toggle-about.js', '', '1.0', true );
       	}
       	add_action( 'wp_enqueue_scripts', 'toggleAbout' );
       ?>
       ```
   
 * And I put this in toggle-about.js:
 *     ```
       jQuery(document).ready(function($){
        $("toggle").click(function(){
         $("#abouttoggle").slideToggle();
         });
       });
       ```
   
 * Thanks for your patience and help with this.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202512)
 * Your webpage is showing blank for me, a blank white screen.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202513)
 * Did you copy the ‘functions.php’ file from the parent theme? If so that may be
   why your site is no longer working, you need to create a new functions.php file.
 *  Thread Starter [mcography](https://wordpress.org/support/users/mcography/)
 * (@mcography)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202517)
 * No, I didn’t. I created a new functions.php. I don’t know what’s going on. I 
   removed functions.php and the site is working again.
 * This is the only code that I had in functions.php:
 *     ```
       <?php
        function toggleAbout() {
        wp_enqueue_script( 'toggle-about', get_stylesheet_directory_uri() . '/js/toggle-about.js', '', '1.0', true );
       	}
         add_action( 'wp_enqueue_scripts', 'toggleAbout' );
       ?>
       ```
   
 * What am I doing wrong?
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/#post-4202521)
 * If you remove that code so that there is absolutely nothing in functions.php (
   of your Child Theme) does your site still break?

Viewing 15 replies - 1 through 15 (of 32 total)

1 [2](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/page/2/?output_format=md)

The topic ‘Javascript Not Working in Child Theme’ is closed to new replies.

## Tags

 * [child](https://wordpress.org/support/topic-tag/child/)
 * [child theme](https://wordpress.org/support/topic-tag/child-theme/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [slideToggle](https://wordpress.org/support/topic-tag/slidetoggle/)
 * [toggle](https://wordpress.org/support/topic-tag/toggle/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 32 replies
 * 2 participants
 * Last reply from: [mcography](https://wordpress.org/support/users/mcography/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/javascript-not-working-in-child-theme-1/page/3/#post-4202550)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
