John John - 1 year ago 70
CSS Question

How can I toggle background color and toggle slide at the same time?

I want to toggle background-color and slideToggle on click. I also want a hover over affect on all buttons. My hover over affect stops working after the first click. I also haven't figured out a good way to toggle background as you will see by my code.

Here is my jsfiddle

This javascript doesn't work if the same button is clicked twice.


Also, if you have any suggestions on how to my my javascipt cleaning/shorter, I'm happy to listen. Thanks.

Answer Source

With a little clean up you can simplify this whole thing a lot:


  .on('click', function () {






button.selected {
  background-color: #ccc;

src: (sorry, at first I forgot to hide the previous slideDown.. this is resolved now)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download