开发者

Toggle jQuery-UI widgets

开发者 https://www.devze.com 2022-12-28 06:22 出处:网络
I have: <div class=\"ui-widget\"> <div class=\"ui-widget-header\"> <span class=\"ui-icon ui-icon-circle-triangle-n\">My Menu</span>

I have:

<div class="ui-widget">
   <div class="ui-widget-header">
      <span class="ui-icon ui-icon-circle-triangle-n">My Menu</span>
   </div>
   <ul class="ui-widget-content">
      <li>Menu Item 1</li>
      <li>Menu Item 2</li>
      <li>Menu Item 3</li>
   </ul>
</div>

My jQuery is:

$('.ui-widget-header').click(function() {
   开发者_运维问答$('.ui-widget-header+ul').toggle('slow');        
});

Q: How do I toggle classes between ui-icon-circle-triangle-n and ui-icon-circle-triangle-s as the user clicks on .ui-widget-header?


Simplest way to do it would be to use .toggleClass()

$('.ui-widget-header').click(function() {
   $('.ui-widget-header+ul').toggle('slow');
   $('.ui-icon', this).toggleClass('ui-icon-circle-triangle-n ui-icon-circle-triangle-s');        
});
0

精彩评论

暂无评论...
验证码 换一张
取 消