Advertisement
fcamuso

Corso recupero Javascript - video 11

Dec 4th, 2022
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.   <title>Document</title>
  8. </head>
  9. <body>
  10.   <div id="div1">
  11.  
  12.     <p id="p1">Questo รจ il primo paragrafo</p>
  13.    
  14.     <p id="p2">Questo รจ il secondo paragrafo</p>
  15.    
  16.     <button>ELIMINA</button>
  17.     <button id="btn">CAMBIA PARAGRAFO</button>
  18.  
  19.    
  20.   </div>
  21.  
  22.   <script>
  23.     const nuovo_p = document.createElement("p");
  24.     nuovo_p.textContent="Nuovo paragrafo";
  25.     nuovo_p.id="pNuovoAfterEnd";
  26.  
  27.     const dopo_questo = document.getElementById("div1");
  28.     dopo_questo.insertAdjacentElement("afterbegin", nuovo_p);
  29.  
  30.     document.getElementById("p1").insertAdjacentHTML("afterbegin", "<b>MODIFICATO</b>");
  31.  
  32.     document.querySelector("button")
  33.       .addEventListener("click", function () {
  34.         document.querySelector("b").remove();
  35.       });
  36.  
  37.     document.getElementById("btn")
  38.       .addEventListener("click", function () {
  39.         const da_spostare = document.querySelector("b");
  40.         document.getElementById("p2").insertAdjacentElement("afterbegin", da_spostare);
  41.  
  42.      });
  43.    
  44.  
  45.  
  46.  
  47.  
  48.   </script>
  49. </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement