有没有办法切换 .append() jQuery 方法? [英] Is there a way to toggle the .append() jQuery method?

查看:45
本文介绍了有没有办法切换 .append() jQuery 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 appendToggle 另一个 img 代替 plus.svg.如果你们知道以某种方式切换 .append() 方法的方法,那就太好了.我想在你点击它的时候改变 CSS,然后再改变它,基本上.

I want to appendToggle another img in place of plus.svg. If you guys know a way to somehow toggle the .append() method, that would be great. I want to change the CSS when you click on it, then change it again, basically.

           $(function(){
            $("#btw").click(function(){
                $("#btwl").slideToggle(300);
                $(this).append("<style>#btw::before{content: url(minus.svg);width: 16px;eight: 16px;background-size: 16px 16px;background-repeat: no-repeat;vertical-align: middle;padding-right: 10px;}</style>");
            });
        });

推荐答案

如果你使用 toggleClass 可以达到同样的效果:

You could achieve the same effect if you use toggleClass:

$(this).toggleClass('selected');

然后在您的 CSS 样式表中执行以下操作:

Then in your CSS stylesheet do something like:

.selected::before {
    content: url(minus.svg);
    width: 16px;
    height: 16px;
    background-size: 16px 16px;
    background-repeat: no-repeat;
    vertical-align: middle;
    padding-right: 10px;
}

来源:http://api.jquery.com/toggleClass/

这篇关于有没有办法切换 .append() jQuery 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆