首页 > 解决方案 > Swap plus and minus on click in ul

问题描述

The problem is when you open one category and than another one , 1st one is close automatic(that is fine) but minus is not change to plus, the content i dynamic generate and this it make little bit hard for me

HTML

{% for category in categories %}
    {% if category.children %}
        <li class="dropdown">
         <a id="mybutton" href="{{ category.href }}" class="dropdown-toggle d-block mybutton" data-toggle="dropdown">{{ category.name }}
            <span class="ttclose hidden-lg" style="float:right"></span>
        </a>
    {% endif %}
{% endfor %}

Jquery

i tired a lot of different ways to do it but didnt find right way

$('.mybutton').on('click', function() {

    if ($(this).children('span').hasClass('ttopen')) {varche = true} else {varche = false};
    if(varche == false){
        $(this).children('span').addClass("ttopen");
        $(this).children('span').removeClass("ttclose");
    $(this).closest('a[aria-expanded="false"]').find('span').removeClass("ttopen");
        varche = true;
    } else
    {
        $(this).children('span').removeClass("ttopen");
        $(this).children('span').addClass("ttclose");
        varche = false;
    }
    });

标签: jquerytwitter-bootstraptwig

解决方案


实际上我是这样做的

$('.dropdown').on('hidden.bs.dropdown', function () {
        $(this).find('span').removeClass('ttopen').addClass('ttclose');
    })

推荐阅读