I'm attempting to create a toggle effect for a background image on a links within an FAQ accordion using javascript.
After referencing this jsfiddle example (http://jsfiddle.net/QwELf/), I was able to get things to function.
You can view my page in action here ()
However, I've encountered an issue when clicking on the toggle links a third time. The background image appears incorrectly and is out of sync with the expected appearance.
In the contracted state, a right arrow '>' should be displayed, and in the expanded state, a downward arrow should appear, but the opposite is happening.
Oddly enough, the jsfiddle example functions properly even on the 3rd or subsequent clicks. Any thoughts on what might be causing the discrepancy with my implementation?
Script
<script type="text/javascript">
function changeArrow(element){
var arrow = element;
if(arrow.className == 'background_one'){
arrow.className = 'background_two';
} else {
arrow.className = 'background_one';
}
}
</script>
CSS
.background_one { text-decoration: none; padding-left: 26px; background: url(http://skmgroupwork.com/suntrust/landingpages/307m/chevright.gif) center left no-repeat;}
.background_two { text-decoration: none; padding-left: 26px; background: url(http://skmgroupwork.com/suntrust/landingpages/307m/chevdown.gif) center left no-repeat;}
HTML
<a class="background_one" data-toggle="collapse" data-target="#demo4" onClick="changeArrow(this)">If I transfer my balance to a new Access 3 Equity Line, what will my interest rate be?</a>