Set expand/collapse background images on headers

I am trying to set a different background image for collapsed and expanded headers on an accordion. Please provide assistance on how I can accomplish this. Jquery: $(document).ready(function() { $('ul#accordion a.heading').click(function() { if($(this).parent().hasClass('current')) { $(this).siblings('ul').slideUp('normal',function() { $(this).parent().removeClass('current'); }); } else { $('ul#accordion li.current ul').slideUp('normal',function() { $(this).parent().removeClass('current'); }); $(this).siblings('ul').slideToggle('normal',function() { $(this).parent().toggleClass('current'); }); } return false; }); }); HTML: CSS: ul#accordion li a.heading { background-color: blue; } ul#accordion li a.headingactive { background-color:red; } I know that my Accordion only covers the click function of the header but I was wondering if I can also incorporate the ready function. So whichever heading is expanded, it will receive the class "headingactive".
Not really clear on what you're asking. When should the heading of the headingactive class? If it's at the same each li element gets the current class, you really don't need a new class since you can style with the selector ul#accordion li.current a.heading (to be overly specific).

以上就是Set expand/collapse background images on headers的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准