开发者

Toggle jQuery-UI widgets

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜