I’ve tried several methods found on this site to get my script to change “+” and “-” expand/collapse button images, but I haven’t yet found a suitable fix/method.
Currently, I am using plain JS as follows:
function swapimg(id) {
if(document.getElementById(id).src='images/bullet_expand.png')
{document.getElementById(id).src='images/bullet_expanded.png'}
else {document.getElementById(id).src='images/bullet_expand.png'}
}
and the button:
<a href="javascript:void();" onclick="toggle_visibility('item1'); swapimg('phb');">
<img src="images/bullet_expand.png" border="0" style="padding-right: 5px;" id="phb" alt="">
</a>
The first click does change the image, but the second click does nothing. I have a feeling using “getElementById” might not be the standard call, so using JQuery is also an option I will consider.
Instead of comparing you are assigning the value, you need
==and not=Instead of this:
use
jQuery:
Javascript: