Advertisement
StavenCross

Banner to Show/Hide content

Aug 12th, 2020
2,414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- create a link for the banner. When its clicked, it will execute the named javascript function in the onclick event-->
  2. <a onclick="toggleTextUnderBanner()"><img src="INSERT IMAGE LINK HERE"></a>
  3. <!-- create a div for all your text to live in. This will be shown/hidden by clicking the banner. You could also include additional images, tables, links, ect. here-->
  4. <div id="toggleTextDiv" style="display:none;"> <!-- the id 'toggleTextDiv' is what our function will look for and modify the css display for. we want to set the inital display value to NONE so its hidden by default. Exclude style="display:none;" and the text will show on page load-->
  5. <!-- input all your text/images/tables/elements you want hidden here before the closing div-->
  6. <p>My toggled Text</p>
  7. <!-- add a "hide text" link to the bottom-->
  8. <p><a onclick="toggleTextUnderBanner()">Click here to hide text</a></p>
  9. </div>
  10. <!--Now we add the javascript. because we're adding a javascript function, this MUST use a RAW html widget-->
  11. function toggleTextUnderBanner() {
  12.     var toggleTextElement = document.getElementById("toggleTextDiv"); //get a reference to your div
  13.         if (toggleTextElement.style.display === "none") { //is it already set to display:none?
  14.         toggleTextElement.style.display = "block"; //force it to display:block instead, which will make it show
  15.     } else {
  16.         toggleTextElement.style.display = "none"; //its currently showing, make it not show instead.
  17.     }
  18. }
  19. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement