Javascript – Uncaught TypeError: .slideToggle is not a function

javascriptjquery

I have jquery in a different file located in the same map, I'm using this code below to activate the .slideToggle function. However it's not working, why?

jQuery(document).ready(function ($) {

    // get li items
    var ul = document.getElementById("menu-footermenu");
    var items = ul.getElementsByTagName("li");

    // display 5 li items, hide others
    for (var i = 0; i < items.length; ++i) {
        if (i > 5) {
            items[i].style.display = "none"
        }
    }

    // when clicking on more catogories button, display all items
    $('#morecat').click(function () {
        for (var i = 0; i < items.length; ++i) {
            if (i > 5) {
                items[i].slideToggle();
                document.getElementById("morecat").style.display = "none";
            }
        }
    });
});

I'm getting the error:

Uncaught TypeError: .slideToggle is not a function

Best Solution

make sure, NOT to use the slim version of jquery, which excludes the effects like the animation.