jquery - 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;
}
});
解决方案
实际上我是这样做的
$('.dropdown').on('hidden.bs.dropdown', function () {
$(this).find('span').removeClass('ttopen').addClass('ttclose');
})
推荐阅读
- google-chrome-extension - 谷歌浏览器扩展中数组的本地存储
- firebase - 使用 firebase 云消息进行地理定位
- c# - 错误 CS0311 从树派生有序树
- c# - 在“PT5M37S”之前没见过这种时间格式
- javascript - 如何从 vueJs 中的对象数组制作对象数组?
- linux-kernel - 无法从 c7 elrepo kernel-lt-4.4.236-1.el7.elrepo.nosrc.rpm 提取内核源 xz
- ruby-on-rails - 带有 2 个参数的 Ruby on Rails 路由未正确路由
- python - Discord.py 机器人不会响应命令...除了它是一个调平系统
- kotlin - Gradle 更改加载失败
- python - 如果文件名的某些字符匹配,如何使用循环从两个目录加载文件?