I am trying to expand/collapse list items. Text will be word followed by definition sort of where definition appears/disappears on click on word. This is my code so far :
<html>
<script type="text/javascript">
function toggleVisibility(listItem) {
var listItemDiv = document.getElementById(listItem);
if(listItemDiv.style.visibility == 'hidden') {
listItemDiv.style.visibility = 'visible';
} else {
listItemDiv.style.visibility = 'hidden';
}
}
</script>
<div onclick="toggleVisibility('p1')">p1</div><div id=p1>p1's text</div></br>
p2<div id=p2>p2's text</div></br>
p3<div id=p3>p3's text</div></br>
p4<div id=p4>p4's text</div></br>
p5<div id=p5>p5's text</div></br>
</html>
However this code hides my text isntead of collapse/expand. I wish to achieve this through javascript preferably.
SOLUTIONS:
OR