开发者

jQuery: Toggling an image when toggling a DIV

I'm trying to write some jQuery that will toggle DI开发者_StackOverflow中文版Vs open and closed, and it's working, but I want an arrow that will change to "down" if the DIV is expanded, and "right" if the DIV is collapsed.

What I have so far:

  $('.toggleHead').click(function() {
   $('#arrow').attr('src', 'images/icons/down.png');
   $(this).next().toggle();
   return false;
  }).next().hide();

Where would I put the other $('#arrow').attr('src', 'images/icons/right.png');?

Thanks!


On #arrow - you can use .toggleClass('open') which will add/remove the 'open' class.

Then in your CSS, you can set a background image for .open which will override the 'down' arrow.

I've got something like

$('.accordion-multi h2').click(function() {
    $(this).next().slideToggle('normal');
    $(this).toggleClass('open');
    return false;
}).next().hide();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜