Advertisement
Guest User

Untitled

a guest
May 4th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta name="apple-mobile-web-app-capable" content="yes">
  7. <meta name="mobile-web-app-capable" content="yes">
  8. </head>
  9. <body>
  10. <p id="toast1" role="alert"></p>
  11. <button onclick="showAlert1();">Show (works) Alert</button>
  12.  
  13. <!-- Dynamically adding role="alert" doesn't work -->
  14. <p id="toast2">This is another alert</p>
  15. <button onclick="showAlert2();">Show (broken) dynamic alert</button>
  16.  
  17. <!-- Creating the toast on the fly and inserting doesn't work -->
  18. <div id="toast3"></div>
  19. <button onclick="showAlert3();">Show (broken) created alert</button>
  20.  
  21. <!-- Setting text to '', then setting back to original content works -->
  22. <p id="toast4" role="alert">This will reload its text in the DOM</p>
  23. <button onclick="showAlert4();">Show (works) reload alert</button>
  24.  
  25. <!-- Doesn't work. Not sure why. Probably because region is hidden -->
  26. <p id="toast5" role="alert" style="visibility: hidden;">This is a timed alert</p>
  27. <button onclick="showAlert5();">Show (broken) timed alert</button>
  28.  
  29. <div id="toast6" role="alert"></div>
  30. <button onclick="showAlert6();">Show timed alert</button>
  31.  
  32. <script>
  33. var toast1 = document.querySelector('#toast1');
  34. function showAlert1() {
  35. toast1.textContent = 'This is an alert';
  36. }
  37.  
  38. var toast2 = document.querySelector('#toast2');
  39. function showAlert2() {
  40. toast2.setAttribute('role', 'alert');
  41. }
  42.  
  43. var toast3 = document.querySelector('#toast3');
  44. function showAlert3() {
  45. var myAlert = document.createElement('p');
  46. myAlert.setAttribute('role', 'alert');
  47. var myAlertText = document.createTextNode('yo yo yo! alert time!');
  48. myAlert.appendChild(myAlertText);
  49. toast3.appendChild(myAlert);
  50. }
  51.  
  52. var toast4 = document.querySelector('#toast4');
  53. function showAlert4() {
  54. var txt = toast4.textContent;
  55. toast4.textContent = '';
  56. toast4.textContent = txt;
  57. }
  58.  
  59. var toast5 = document.querySelector('#toast5');
  60. function showAlert5() {
  61. setTimeout(function() {
  62. var txt = toast5.textContent;
  63. toast5.style.visibility = 'visible';
  64. toast5.textContent = '';
  65. toast5.textContent = txt;
  66. }, 1000);
  67. }
  68.  
  69. var toast6 = document.querySelector('#toast6');
  70. function showAlert6() {
  71. setTimeout(function() {
  72. var toast = document.createElement('p');
  73. toast.setAttribute('role', 'alert');
  74. var txt = document.createTextNode('this is a timed alert');
  75. toast.appendChild(txt);
  76. toast6.appendChild(toast);
  77. }, 1000);
  78. }
  79. </script>
  80. </body>
  81. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement