user38208
user38208

Reputation: 1094

Adding jQuery code to wordpress

I am trying to add the following code to Wordpress but it doesn't seem to work. The same code in a fiddle works.

Please help.

$(".box").hover(

function (e) {
$('.box').not(this).addClass('grey')

}, // over
function (e) {
$('.box').removeClass('grey')

} // out
);

Upvotes: 1

Views: 65

Answers (1)

Erwin
Erwin

Reputation: 1502

You have to wrap it in the noConflict mode. Like:

jQuery(function($){
// Your jQuery code here, using the $
});

See: http://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/

So, that would boil down to

jQuery(function($){
    $(".box").hover( function (e) {
         $('.box').not(this).addClass('grey');    
    }, // over
    function (e) {
         $('.box').removeClass('grey');    
    } // out
);
});

Upvotes: 1

Related Questions