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'm following a tutorial.

I've included the hover.js with the following code:

$(function() {
    // OPACITY OF BUTTON SET TO 50%
    $(".imgopacity").css("opacity","0.5");

    // ON MOUSE OVER
    $(".imgopacity").hover(function () {
        // SET OPACITY TO 100%
        $(this).stop().animate({
            opacity: 1.0
        }, "slow");
    },

    // ON MOUSE OUT
    function () {
        // SET OPACITY BACK TO 50%
        $(this).stop().animate({
            opacity: 0.5
        }, "slow");
    });
});
share|improve this question
2  
replace the first $(function() { with jQuery(document).ready(function($){ –  onetrickpony Oct 5 '11 at 11:45
    
@OneTrickPony Those two pieces of syntax are equivalent, the former being shorthand for the latter. –  Annika Backstrom Oct 5 '11 at 13:21
1  
@AdamBackstrom - it's not quite the same. The second enables jQuery to be called using the $ namespace. –  f0x Oct 5 '11 at 13:26

2 Answers 2

up vote 5 down vote accepted

Going through your source - jQuery Source - it seeems that noConflict() is getting called right at the end.

To fix your hover.js then would look something like this:

jQuery(function($) {    //Allow the use of $ namespace in this function.
    // OPACITY OF BUTTON SET TO 50%
    $(".imgopacity").css("opacity","0.5");

    // ON MOUSE OVER
    $(".imgopacity").hover(function () {

    // SET OPACITY TO 100%
    $(this).stop().animate({
        opacity: 1.0
        }, "slow");
   },

    // ON MOUSE OUT
   function () {

   // SET OPACITY BACK TO 50%
   $(this).stop().animate({
       opacity: 0.5
       }, "slow");
   });
});

Regards,

share|improve this answer
    
I've read somewhere that I need to change all instances of $ to Jquery, I tried that but it didn't work.. For the code you sent, what does this mean: jQuery(function($) { and why did it work? thanks! –  Laurize Oct 5 '11 at 23:39
1  
@Laurize, the reason it worked is because jQuery(function($) { basically means the following; A function that will use the jQuery library but allow $ to reference jQuery instead (and not some other library that has been added.) See the $ in the parameter of the anonymous function in your snippet. Ciao! –  f0x Oct 6 '11 at 6:08

Do not use "$()" in Wordpress use "jQuery()" instead.

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.