简体   繁体   English

jquery,切换css内容(向上和向下箭头)

[英]jquery, toggle css content (arrow up and down)

I use jquery to toggle an element. 我使用jquery来切换元素。 the button that i use is styled with css. 我使用的按钮是用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) ). 我想根据切换元素的状态( $(#categories ul) )更改内容,从\\25BC (向下箭头)到\\25B2 (向上箭头)。
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();
      });
   });

CSS: CSS:

a#categories-toggle.down:after{
  content: "\25BC";
}
a#categories-toggle:after{
  content: "\25B2";
}

HTML: HTML:

<a id="categories-toggle" href="#">foo</a>

jQuery: jQuery的:

$("#categories-toggle").on('click', function(eve){
     eve.preventDefault(); 
     $(this).toggleClass("down");
  });

Have you tried $('a#categories-toggle').css('content', '\\25B2'); 你试过$('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. ToggleClass可以在空格分隔的类之间切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM