admin管理员组文章数量:1026989
I use jquery to toggle an element. the button that i use is styled with css.
I want to change the content, from \25BC
(arrow down) to \25B2
(arrow up), based on the state of the toggled element ($(#categories ul)
).
How should it be done?
the code:
a#categories-toggle:after{
content: "\25BC";
}
$().ready(function(){
$("#categories-toggle").on('click', function(eve){
eve.preventDefault();
$("#categories ul").toggle();
});
});
I use jquery to toggle an element. the button that i use is styled with css.
I want to change the content, from \25BC
(arrow down) to \25B2
(arrow up), based on the state of the toggled element ($(#categories ul)
).
How should it be done?
the code:
a#categories-toggle:after{
content: "\25BC";
}
$().ready(function(){
$("#categories-toggle").on('click', function(eve){
eve.preventDefault();
$("#categories ul").toggle();
});
});
Share
Improve this question
asked Jun 22, 2014 at 20:01
yossiyossi
3,1647 gold badges48 silver badges70 bronze badges
2
- If you want to toggle the content, using CSS pseudo classes to add the content seems like one of the worst ideas ever. – adeneo Commented Jun 22, 2014 at 20:09
- @adeneo why?! i want to toggle the content of the :AFTER – yossi Commented Jun 22, 2014 at 20:12
3 Answers
Reset to default 10CSS:
a#categories-toggle.down:after{
content: "\25BC";
}
a#categories-toggle:after{
content: "\25B2";
}
HTML:
<a id="categories-toggle" href="#">foo</a>
jQuery:
$("#categories-toggle").on('click', function(eve){
eve.preventDefault();
$(this).toggleClass("down");
});
Have you tried $('a#categories-toggle').css('content', '\25B2'); ?
a#categories-toggle.up:after{
content: "\25BC";
}
a#categories-toggle.down:after{
content: "\25B2";
}
$().ready(function(){
$("#categories-toggle").on('click', function(eve){
eve.preventDefault();
$("#categories ul").toggleClass(up down);
});
});
ToggleClass can switch between space seperated classes.
I use jquery to toggle an element. the button that i use is styled with css.
I want to change the content, from \25BC
(arrow down) to \25B2
(arrow up), based on the state of the toggled element ($(#categories ul)
).
How should it be done?
the code:
a#categories-toggle:after{
content: "\25BC";
}
$().ready(function(){
$("#categories-toggle").on('click', function(eve){
eve.preventDefault();
$("#categories ul").toggle();
});
});
I use jquery to toggle an element. the button that i use is styled with css.
I want to change the content, from \25BC
(arrow down) to \25B2
(arrow up), based on the state of the toggled element ($(#categories ul)
).
How should it be done?
the code:
a#categories-toggle:after{
content: "\25BC";
}
$().ready(function(){
$("#categories-toggle").on('click', function(eve){
eve.preventDefault();
$("#categories ul").toggle();
});
});
Share
Improve this question
asked Jun 22, 2014 at 20:01
yossiyossi
3,1647 gold badges48 silver badges70 bronze badges
2
- If you want to toggle the content, using CSS pseudo classes to add the content seems like one of the worst ideas ever. – adeneo Commented Jun 22, 2014 at 20:09
- @adeneo why?! i want to toggle the content of the :AFTER – yossi Commented Jun 22, 2014 at 20:12
3 Answers
Reset to default 10CSS:
a#categories-toggle.down:after{
content: "\25BC";
}
a#categories-toggle:after{
content: "\25B2";
}
HTML:
<a id="categories-toggle" href="#">foo</a>
jQuery:
$("#categories-toggle").on('click', function(eve){
eve.preventDefault();
$(this).toggleClass("down");
});
Have you tried $('a#categories-toggle').css('content', '\25B2'); ?
a#categories-toggle.up:after{
content: "\25BC";
}
a#categories-toggle.down:after{
content: "\25B2";
}
$().ready(function(){
$("#categories-toggle").on('click', function(eve){
eve.preventDefault();
$("#categories ul").toggleClass(up down);
});
});
ToggleClass can switch between space seperated classes.
本文标签: JavaScriptJQuerytoggle css content (arrow up and down)Stack Overflow
版权声明:本文标题:javascript - jquery, toggle css content (arrow up and down) - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1740309485a1749336.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论