Advertisement
fcamuso

Corso recupero Javascript - video 13

Jan 12th, 2023
1,144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. //ESERCIZIO 4
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5.   <meta charset="UTF-8">
  6.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.   <title>Document</title>
  9. </head>
  10. <body>
  11.   <p>Sono un paragrafo</p>
  12.  
  13.   <button>Bottone</button>
  14.   <a href="www.camuso.it"> Vai al sito del prof.</a>
  15.   <b>Importante!</b>
  16.   <img src="img/imm1.JPG">
  17.  
  18.   <script>
  19.     window.addEventListener("click", function() {
  20.       if(document.body.lastElementChild.previousElementSibling!==null)
  21.         document.body.lastElementChild.previousElementSibling.remove();    
  22.     });
  23.  
  24.   </script>
  25. </body>
  26. </html>
  27.  
  28.  
  29. //ESERCIZIO 5
  30. <!DOCTYPE html>
  31. <html lang="en">
  32. <head>
  33.   <meta charset="UTF-8">
  34.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  35.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  36.   <title>Document</title>
  37. </head>
  38. <body>
  39.   <p>Sono un paragrafo</p>
  40.  
  41.   <button>Bottone</button>
  42.   <a href="www.camuso.it"> Vai al sito del prof.</a>
  43.   <b>Importante!</b>
  44.   <img src="img/imm1.JPG">
  45.  
  46.   <script>
  47.     //array con i riferimenti di tutti gli elementi figli del body
  48.     let figli_del_body = document.querySelectorAll("body>*");
  49.  
  50.     //escludiamo questo stesso script
  51.     for (let i=0; i<figli_del_body.length - 1; i++)
  52.       figli_del_body[i].addEventListener("click", function (e) {
  53.         e.preventDefault();
  54.         this.remove();
  55.       })
  56.  
  57.   </script>
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement