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.

I am using wp_enqueue_script to do this. If I try to do something else lets say popup a dialog, it works but the code below does not. Can someone tell me the problem. thanks.

var $j = jQuery.noConflict();
    $j('#mystuff').hide();
    var mouseLastYPos = null;
    $j(document).mousemove(function(e){ 
        if(mouseLastYPos){ 
            if (e.pageY < mouseLastYPos && e.pageY <= 2){

               $j('#mystuff').show();

            }
        }
        mouseLastYPos = e.pageY;
    });​

here is a working demo of this code on a static page. when you move you mouse to the top of the page some text appears. http://jsfiddle.net/bmHbt/

share|improve this question
    
most likely a css error with your WordPress layout. If you don't post your WordPress code it's going to be hard to help. –  BandonRandon Apr 27 '12 at 19:51

1 Answer 1

up vote 4 down vote accepted

The jQuery library included with WordPress loads in "no conflict" mode. This is to prevent compatibility problems with other javascript libraries that WordPress can load.

In order to use the default jQuery shortcut of $, you can use the following wrapper around your code:

jQuery(document).ready(function($) {
    // $() will work as an alias for jQuery() inside of this function
});

That wrapper will cause your code to be executed when the page finishes loading, and the $ will work for calling jQuery. If, for some reason, you want your code to execute immediately (instead of waiting for the DOM ready event), then you can use this wrapper method instead:

(function($) {
    // $() will work as an alias for jQuery() inside of this function
})(jQuery);
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.