To use this just simply add this code where you want it.
<div id="spoiler" style="display:none">
HIDDEN CONTENT HERE
</div>
<button title="Click to show/hide content" type="button"
onclick="if(document.getElementById('spoiler')
.style.display=='none') {document.getElementById('spoiler')
.style.display=''}else{document.getElementById('spoiler')
.style.display='none'}">BUTTON TEXT</button>
HIDDEN CONTENT HERE
</div>
<button title="Click to show/hide content" type="button"
onclick="if(document.getElementById('spoiler')
.style.display=='none') {document.getElementById('spoiler')
.style.display=''}else{document.getElementById('spoiler')
.style.display='none'}">BUTTON TEXT</button>
Just replace the Blue text with the content or code you want to hide. Replace the Red text with the name you want to display on the button. Now with the Orange text you can leave it the same if you plan to use this one time on a page. But if you want to use this multiple times on the same page you will need to change them each to a different name. If you look in the code below you can see how I had to use spoilor1 instead to get it to display.
Here is a Example:
Now maybe you want the content to display by default and only hide when clicked on. If that is the case use this code below.
<div id="spoiler1">
CONTENT TO HIDE
</div>
<button title="Click to show/hide content" type="button" onclick="if(document.
getElementById('spoiler1') .style.display=='') {document.getElementById('spoiler1') .style.display='none'}else{document.getElementById('spoiler1') .style.display=''}">BUTTON TEXT</button>
CONTENT TO HIDE
</div>
<button title="Click to show/hide content" type="button" onclick="if(document.
getElementById('spoiler1') .style.display=='') {document.getElementById('spoiler1') .style.display='none'}else{document.getElementById('spoiler1') .style.display=''}">BUTTON TEXT</button>
Example:
CONTENT TO HIDE
Now maybe you want something a little better the a simply gray button. Well you can use a image instead by replacing the BUTTON TEXT with this code below.
Thanks so much! Now, is there a way to make several show/hide content buttons, but when one is shown and you want to show another one, the first hides itself automatically? Thanks! LUCAS.-
ReplyDeleteYou need to enter a separate ID (orange) for the 2nd spoiler button.
ReplyDeleteI'm trying to use this for my video based blog to keep people from being overwhelmed by 10+ videos loading all at once.
ReplyDeleteBut when I try the first method, which is what I'd prefer, the first video keeps repeating over and over again.
The second one works but again, I don't want the videos loading all at once. Is there something I'm doing wrong?
Any tips on making this work in Internet Explorer?
ReplyDeleteI've been looking for days for a hack that will (1) work and (2) not complicate my life. Others required me to do some tweaking on the main template as well. Yours just have to be appended on the page you where the hide/show functionality is needed.
ReplyDeleteThanks so much for sharing. You just made my day.
Love this feature! Have been looking for this for awhile.
ReplyDeleteTwo questions for ya:
1. Is it possible to have the hidden content display below the button?
2. Is it possible to have the button text to display "SHOW" when the content is hidden and "HIDE" when the content is revealed?
Thanks so much!!
-Jess
Hi Jess,
ReplyDeleteYou can have the button on top of the content by moving the the div section to the bottom of the code. This means everything in the first 3 lines of coding gets moved to the bottom.
As for the button alternating when being clicked on I do not believe their is a way to do so while keeping this a simple tweak. As you might of seen Admins comment above you, their are other ways to do this online in which requires you to do some hard coding directly into the template. These are much harder to do but may provide the alternating button that your looking for.
Very awesome! I run three website with spoiler content. This helps out tremendously. Thanks!
ReplyDeletePlot Spoiler
What do I do if I want to have this HIDE/SHOW button appear by default in every one of my posts? I am a food blogger and want to be able to show/hide recipes.
ReplyDeleteThe only way I know to do that would be by using the old Blogger interface and you will find a option in your settings called formatting. Within the formatting their should be a box titled post template where you can add the code. This will add the code to all new post within the post editor.
ReplyDelete