开发者

simple jquery function doesn't work when included in wordpress? help?

开发者 https://www.devze.com 2023-04-08 09:21 出处:网络
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

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).r开发者_开发问答eady(function(){
    $(".slideright img").removeClass("ngg-singlepic").addClass("cover");
    //$(".ngg-singlepic").addClass("cover");
});


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消