0

I'm replacing class name generated by one of the plugins with mine. I found this easier than fiddling with plugin on every upgrade. Anyways, in WP this simply doesn't do anything! When I test it on non wp (same template xhtml) it works!

what could be the conflict? I have jquery included.

$(document).ready(function(){
 $(".slideright img").removeClass("ngg-singlepic").addClass("cover");
 //$(".ngg-singlepic").addClass("cover");
});
asked Sep 23, 2011 at 7:55

2 Answers 2

2

Try this:

jQuery(document).ready(function($){
 $(".slideright img").removeClass("ngg-singlepic").addClass("cover");
 //$(".ngg-singlepic").addClass("cover");
});

The problem is that I think wordpress includes other libraries that conflict with the $ when used with jquery.

To get around this you need to explicitly call jQuery the first time and if you pass $ into the function then it will let you use the familiar $ within the scope of the jquery function.

Hope that helps.

answered Sep 23, 2011 at 7:57
Sign up to request clarification or add additional context in comments.

2 Comments

nice, thank you also for explaining... I'm learning allot these days :)
thats ok. :) I'm getting into the habit of ALWAYS doing jQuery(document).ready(function($){...}); now, even outside of wordpress. Just incase in the future compatibility is needed with other libraries. :) Its a good habit to get into I think. :)
1

Maybe there is some other framework included in your page. Try the following:

jQuery( function($) {
 $(".slideright img").removeClass("ngg-singlepic").addClass("cover");
});

And if that does not help, you can even try to put jQuery.noConflict(); before the snippet.

answered Sep 23, 2011 at 7:58

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.