Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I place the following javaScript in the <head> section of the Wordpress Widgets API menu screen?

<script type="text/javascript">
    jQuery(window).load(function() {
        jQuery("#logocheckbox").change(function() {
            jQuery("#logocheckboxdiv").fadeToggle("slow");
        });
    });
</script>
share|improve this question
    
I didn't dig through your PHP code, as this sounds like it's a jQuery related issue. The jsFiddle works, and assuming you're using the same approach, are you sure that the jQuery Selector is correct in the WP Admin Widgets screen? Perhaps your selector doesn't match any elements and therefore the contents do not appear when checkbox is ticked. EDIT Scrap that, I just noticed your jQuery code at the bottom of that functions.php codeblock. The selector seems to be fine. –  Marc Dingena Mar 26 '13 at 15:27
    
Using WordPress Debugging, I'm getting the following Notices -- Notice: Undefined index: checkbox in /wp-content/themes/twentyeleven/functions.php on line 299 Notice: Undefined index: select in /wp-content/themes/twentyeleven/functions.php on line 300 More importantly, my browser is outputting an Uncaught TypeError, but I will post that as my answer. –  Marc Dingena Mar 26 '13 at 15:50
    
Multi-post: stackoverflow.com/q/15637431 See: meta.stackexchange.com/q/64068 –  brasofilo Mar 26 '13 at 16:38

2 Answers 2

Uncaught TypeError: Property '$' of object [object Object] is not a function

Are you positive you're accessing the jQuery object correctly? You should look into how WordPress uses noConflict mode.

In the noConflict() mode, the global $ shortcut for jQuery is not available, but you can still use:

jQuery(document).ready(function(){
    jQuery(#somefunction) ...
});

As a footnote, as a developer, whether it's for themes or plugins, you should make use of development tools that are at your disposal. Your browser likely has a Developer Tool or Console that will show you anything that's wrong with your code. WordPress Debugging will also flag any errors that might still work, but are technically incorrect code.

share|improve this answer
up vote 0 down vote accepted
function load_custom_logo_js($hook) {   
     if( 'widgets.php' != $hook )
         return;

     echo ('
     <script type="text/javascript">
        jQuery(window).load(function() {
            jQuery("#logocheckbox").change(function() {
                jQuery("#logocheckboxdiv").fadeToggle("slow");
             });
         });
     </script>
     ');

}

add_action( 'admin_enqueue_scripts', 'load_custom_logo_js' ); 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.