I am trying to create a link <a>
with two different backgrounds, one a "Down Arrow" and one an "Up Arrow" depending on the classname arrow-up
and arrow-down
.
So when you click on the down arrow, the div named product-add-wrapper
slides down, and the down arrow* becomes an **up arrow and vice versa.
The problem is, the .toggle + callback seems to work fine, it adds the desired class name and removes the desired class name, however, the background-image doesn't change (the down arrow doesn't become an up arrow).
Here is the html.
<span class="arrow-right">
<a class="updown arrow-down"> </a>
</span>
Here is the css.
.updown {
display: block;
margin-top: -1px;
height: 25px;
width: 25px;
}
.arrow-up {
background-image: url('../img/arrow-up.png');
}
.arrow-down {
background-image: url('../img/arrow-down.png');
}
And here is the javascript.
$('.updown').click(function() {
$('#product-add-wrapper').toggle('slow', function() {
var classname = $('.updown').attr('class');
if (classname === 'up arrow-down') {
$('.updown').removeClass('arrow-down').addClass('arrow-up');
} else {
$('.updown').removeClass('arrow-up').addClass('arrow-down');
}
});
});
Any ideas? Thanks in advance.