最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - .slideToggle() not working when using Jquery 3.1.1 - Stack Overflow

programmeradmin6浏览0评论

For some reason I am getting an Uncaught TypeError when I try and execute the following code.

jQuery(function($){
    $(document).ready(function() {
        $(".block").click(function() {
            var currentElement = $(this).find(".form-group");
            currentElement.slideToggle("slow");
        });
    });
});

I get the following error

Uncaught TypeError: currentElement.slideToggle is not a function
at HTMLDivElement.<anonymous> (index.js:6)
at HTMLDivElement.dispatch (jquery-3.1.1.slim.min.js:3)
at HTMLDivElement.q.handle (jquery-3.1.1.slim.min.js:3)

However when I call currentElement.toggle() It works as expected and I do not get any errors.

Can anyone explain why this is?

For some reason I am getting an Uncaught TypeError when I try and execute the following code.

jQuery(function($){
    $(document).ready(function() {
        $(".block").click(function() {
            var currentElement = $(this).find(".form-group");
            currentElement.slideToggle("slow");
        });
    });
});

I get the following error

Uncaught TypeError: currentElement.slideToggle is not a function
at HTMLDivElement.<anonymous> (index.js:6)
at HTMLDivElement.dispatch (jquery-3.1.1.slim.min.js:3)
at HTMLDivElement.q.handle (jquery-3.1.1.slim.min.js:3)

However when I call currentElement.toggle() It works as expected and I do not get any errors.

Can anyone explain why this is?

Share Improve this question edited Mar 7, 2017 at 16:55 DaniP 38.3k9 gold badges67 silver badges74 bronze badges asked Mar 7, 2017 at 16:34 LennyLenny 1932 silver badges12 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 8

The problem here is you are using the slim version which excludes the effects like the animation expected from slideToggle; so the function isn't defined. Just switch to the normal version.

From the Jquery Page

Slim build

Sometimes you don’t need ajax, or you prefer to use one of the many standalone libraries that focus on ajax requests. And often it is simpler to use a bination of CSS and class manipulation for all your web animations. Along with the regular version of jQuery that includes the ajax and effects modules, we’ve released a “slim” version that excludes these modules. All in all, it excludes ajax, effects, and currently deprecated code.

发布评论

评论列表(0)

  1. 暂无评论