tags:

views:

27

answers:

2

I use slideToggle to toggle div's of content and I was wondering how I would be able to change between two images, one being a plus (+) sign, to click to display the content and a minus (-) sign to hide the content.

Any help is appreciated.

This is what I have to toggle one of the div's

$(document).ready(function() {
 $('#planning-click').click(function() {
  $("#planning").slideToggle(100);
 });
});
A: 

You can simply change the src on the image and it should update. So you just add

$(link).attr('src', urlForNewimage);

inside of your click function there.

And then how would it revert back to the original on a subsequent click?
Marko
The same way:$(link).attr('src', urlForOldImage);though class toggling is probably a simpler solution, as you never have to know which image to use, it will automatically use the correct one.
+2  A: 

Use the toggleClass method on the link and change it's bacgkround accordingly.

$(document).ready(function() {
 $('#planning-click').click(function() {
  $("#planning").slideToggle(100);
  $(this).toggleClass("open");
 });
});

#planning-click {
    background: url(minus.png) no-repeat;
}
.open {
    background-image: url(plus.png);
}
Marko