Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Accordion</title>
  6. <style>
  7. #accordion {
  8. border: 1px solid black;
  9. display: inline-block;
  10. width: 400px;
  11. }
  12.  
  13. #accordion p {
  14. margin: 1em;
  15. }
  16.  
  17. .button {
  18. float: right;
  19. background: #5555ff;
  20. padding: 0.1em 1em 0.1em 1em;
  21. color: white;
  22. cursor: pointer;
  23. }
  24.  
  25. #extra {
  26. display: none;
  27. }
  28.  
  29. .head {
  30. background: #ccccff;
  31. padding: 1em;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <div id="accordion">
  37. <div class="head">DOM Manipulations Exercise <span class="button" onclick="toggle()">More</span></div>
  38. <div id="extra">
  39. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  40. </div>
  41. </div>
  42. <script>
  43. function toggle() {
  44. let button = document.getElementsByClassName('button')[0];
  45.  
  46. if (button.textContent === "Less") {
  47. document.getElementById("extra").style.display ="none";
  48. button.textContent = "More";
  49. } else if (button.textContent === "More") {
  50. document.getElementById("extra").style.display ="inline";
  51. button.textContent = "Less"
  52. }
  53. }
  54. </script>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement