Magento 1.9 – TypeError: this.toggleElements.toggleSingle is not a function

The question:

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?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

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});
        }
    }

Method 2

the answer of jelle siderius doesn’t work on my magento installation. I’ve fixed it, in changing this line

jQuery.fn.toggleSingle = function (options) {

in

$j.fn.toggleSingle = function (options) {


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment