Magento 1.9 – Fix TypeError: this.toggleElements.toggleSingle is Not a Function

magento-1.9

I am a developer Magento themes but I'm still learning how to work with the theme rwd.

I am getting a javascript error (below) when I see our store smaller screens resolution.

TypeError: this.toggleElements.toggleSingle is not a function
this.toggleElements.toggleSingle();

I don't understand the function below. I have copied the rdw package files to make the package from our store and have not changed any html tag in any of these files, just added my classes for CSS usage.

enquire.register('(max-width: ' + bp.medium + 'px)', {
    setup: function () {
        this.toggleElements = $j(
            // This selects the menu on the My Account and CMS pages
            '.col-left-first .block:not(.block-layered-nav) .block-title, ' +
                '.col-left-first .block-layered-nav .block-subtitle--filter, ' +
                '.sidebar:not(.col-left-first) .block .block-title'
        );
    },
    match: function () {
        this.toggleElements.toggleSingle();
    },
    unmatch: function () {
        this.toggleElements.toggleSingle({destruct: true});
    }
});

What can be causing this error?

Best Answer

I have had the same problem. Fixed it by checking the length of the element which needs to be toggled. The best thing you could do is rewrite this javascript file in your custom Magento theme that you use and add this code.

    match: function () {
        if(this.toggleElements.length > 0){
            this.toggleElements.toggleSingle();
        }
    },
    unmatch: function () {
        if(this.toggleElements.length > 0){
            this.toggleElements.toggleSingle({destruct: true});
        }
    }