How to toggle two images onClick

image, javascript, onclick, treeview

Solution

This should work:

<style>
.expand{
    content:url("http://site.com/expand.gif");
}
.collapse{
    content:url("http://site.com/collapse.gif");
}
</style>

<img class="expand">
<script>
//onclick code
$('img.expand').toggleClass('collapse');
</script>

Problem

I'm making a collapsible treeView. I made it all, I just need my `+` and `-` icons to toggle whenever they are clicked. I did the part when I change an icon from `+` to `-`, on click, with jQuery with the following code: ``` $(this).attr('src','../images/expand.gif'); ``` Problem is, I don't know how to make it go other way around, when i click on the node again :)

Original source

Related problems