0

I want to active an accordion tab on button click with activate() method https://devdocs.magento.com/guides/v2.1/javascript-dev-guide/widgets/widget_tabs.html#fedg_tabs_methods-activate

This is my test code

<div id="element">
        <div class="custom_collapsible">
            <div class="custom_trigger">
                <span>Title 1</span>
            </div>
        </div>
        <div class="custom_content">Content 1</div>

        <div class="custom_collapsible">
            <div class="custom_trigger">
                <span>Title 2</span>
            </div>
        </div>
        <div class="custom_content">Content 2</div>

        <div class="custom_collapsible">
            <div class="custom_trigger">
                <span>Title 3</span>
            </div>
        </div>
        <div class="custom_content">Content 3</div>
    </div>

    <button id="btn">Activate 1</button>
    <script>

        if (2 == 2) {
            var collapsible = true
        } else {
            var collapsible = false
        }

        require([
            'jquery',
            'accordion'], function ($) {
            $('#btn').click(function() {
                $("#element").accordion().activate(2);
            });
            $("#element").accordion({
                active: [0,1],
                closedState: "accordion-closed",
                collapsible : collapsible, 
                collapsibleElement : ".custom_collapsible", 
                content : ".custom_content",
                disabled : [2],
                disabledState : "accordion-disabled",
                trigger : ".custom_trigger",
                icons: {"header": "plus", "activeHeader": "minus" }

            });
        });
    </script>

but i get this error

Uncaught TypeError: $(...).accordion(...).activate is not a function

what i'm wrong?

0

This is right way

$('#btn').click(function() {
    $("#element").accordion("activate", [1]);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.