I installed this jsfiddle for you, click on the header and the contents will display:
jsfiddle
Basically, with the onclick event of the title, you decide whether to show or hide the content, and you change the title to change the +/- characters. Of course, this example only shows how to implement logic, but beautiful styles are not applied to it.
html:
<div class='collapsibleCont'> <h3 id='collapsible1' class='collapsibleTitle' onclick="handleCollapsible('collapsible1')">+ title</h3> <p style="display:none" class='collapsibleContent'>helloooooooooooo</p> </div>
function handleCollapsible (id):
function handleCollapsible(id){ var clickedTitle = document.getElementById(id); var contentC = clickedTitle.parentNode.childNodes[1]; if(contentC.style.display=='none'){ contentC.style.display = 'block'; var mysplittedtitle = clickedTitle.innerHTML.split(" "); var newTitle = "- "+mysplittedtitle[1]; clickedTitle.innerHTML =newTitle; }else{ contentC.style.display = 'none'; var mysplittedtitle = clickedTitle.innerHTML.split(" "); var newTitle = "+ "+mysplittedtitle[1]; clickedTitle.innerHTML=newTitle; } }
Doing this with jquery would be a lot easier. Doing this with jquery-mobile would be a lot easier. The bad thing about this code is the need to add an onclick event to each minimized, including an identifier that can be avoided and is much easier with jquery.
source share