Advertisement
1xptolevitico69

Display Html Class content Onclick

Nov 12th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.09 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title></title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <style>
  8.  
  9. h1 { font-family:courier;  }
  10. button {  color:white;background-color:navy; padding:5px 20px;  
  11.           outline:none;font-size:20px;font-weight:900;  }
  12. .info {  display:none; }
  13.  
  14. </style>
  15. </head>
  16. <body>
  17. <button onclick='info()'>Display Info</button>
  18.  
  19. <h2 class='info'>John 32 years old has broken both legs.</h2>
  20. <h2 class='info'>Henrietta 40 year old, single, wants to die right now.</h2>
  21. <h2 class='info'>Marcus 10 years old has eaten his own pet chicken.</h2>
  22.  
  23. <h1 id='h1'></h1>
  24.  
  25. <script>
  26. i=0;
  27.  
  28.      x = document.getElementsByClassName('info');
  29.  
  30. function info(){
  31. del=setInterval(()=>{
  32. h1.innerHTML+=x[i].innerHTML+'<br>';
  33. h1.style.display='block';
  34. i++;
  35. if(i==x.length){
  36. clearInterval(del);
  37. setTimeout(function(){
  38. h1.innerHTML+='<span style="font-size:20px;font-family:courier;"><a href="https://www.w3schools.com/tags/att_global_class.asp" target="_blank">End of results.</a></span>';
  39. },500);
  40. }
  41. },500);
  42. }
  43.  
  44. </script>
  45. </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement