简体   繁体   English

jQuery addClass现在不能正常工作

[英]jQuery addClass is not working now

So I'm trying to add a class with jquery. 所以我试图用jquery添加一个类。 Here is the code: 这是代码:

jQuery(document).ready(function($) {
    $('body').addClass('scrollbar-dynamic');
});

I can confirm the script is loaded on frontend as it appears in source code. 我可以确认脚本是在前端加载的,因为它出现在源代码中。 Plus all other javascript "1400 lines" works fine. 加上所有其他javascript“1400行”工作正常。 The addClass jquery method is also used about 30 more times throughout the script. addClass jquery方法在整个脚本中也使用了大约30次。 I'm also using the latest version of wordpress It's just this time it's not working. 我也在使用wordpress的最新版本。这次它不起作用。 Here is a working js fiddle 这是一个工作的小提琴

Stuff like this just drives me crazy. 像这样的东西只会让我发疯。 Cheers for the help 干杯求救

Ok - since console.log(jQuery) is returning what we'd expect, I think the issue is with how the library is being referenced. 好的 - 因为console.log(jQuery)正在返回我们期望的内容,我认为问题在于如何引用库。 Here's your code: 这是你的代码:

jQuery(document).ready(function($) {
  $('body').addClass('scrollbar-dynamic');
});

The script knows what jQuery is...but it doesn't seem to know what $ is, and it's not being bound to anything when it's called. 脚本知道jQuery是什么......但它似乎并不知道$是什么,并且在调用时它并没有受到任何约束。

Try this - if it works, it's a binding issue. 试试这个 - 如果它有效,这是一个约束性的问题。

jQuery(document).ready(function($) {
  jQuery('body').addClass('scrollbar-dynamic');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM