有没有一种方法来切换.append()方法的jQuery? [英] Is there a way to toggle the .append() jQuery method?
本文介绍了有没有一种方法来切换.append()方法的jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要appendToggle另一IMG到位plus.svg的。如果你们知道的方式以某种方式切换 .append()
的方法,那将是巨大的。我想改变的CSS,当你点击它,然后再改变它,基本上是这样。
$(函数(){
$(#BTW)。点击(函数(){
$(#btwl)的slideToggle(300)。
$(本).append(<风格> #btw :: {前内容:网址(minus.svg);宽度:16px的;八:16像素;背景-SIZE:16px的16px的;背景重复:不重复;垂直对齐:中;填充右:10px的;}< /风格与GT;);
});
});
解决方案
您可以如果您使用达到同样的效果 toggleClass
:
$(本).toggleClass('选择');
然后在你的CSS样式表做这样的事情:
.selected :: {前
内容:网址(minus.svg);
宽度:16px的;
高度:16px的;
背景-SIZE:16px的16px的;
背景重复:不重复;
垂直对齐:中间;
填充右:10px的;
}
来源: http://api.jquery.com/toggleClass/
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>");
});
});
解决方案
You could achieve the same effect if you use toggleClass
:
$(this).toggleClass('selected');
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;
}
Source: http://api.jquery.com/toggleClass/
这篇关于有没有一种方法来切换.append()方法的jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文