I have a really simple function that should:
- change the wording (from expand to collapse)
- change the style (visibility) for a class
It sorta works but really not
function toggle_expansion(id) {
var e = document.getElementById(id);
var es =getElementsByClass('expansion');
if (e.innerHTML ='expand all') {
e.innerHTML ='collapse all';
for(i=0; i<es.length; i++)
{es[i].style.display = 'none';}
}
else {
e.innerHTML ='expand all';
for(i=0; i<es.length; i++)
{es[i].style.display = 'block';}
}
}
and the html:
<a href='#nogo' onclick="toggle_expansion('expand');"><div id='expand'>expand all</div></a>
The text change works the first time it’s clicked but only the one time and the class style change doesn’t work (although it has worked in other snippets).
There are no errors thrown – it just doesn’t work…Anyone have any ideas?
should be