Advertisement
fcamuso

Javascript Lezione 44

May 26th, 2022
1,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.     let immagini = Array.from(document.getElementsByTagName("img"));    
  3.     let dropDownImmagini = document.createElement("select");
  4.     dropDownImmagini.id="elencoImmagini";
  5.  
  6.     immagini.forEach((immagine,indice) => {
  7.       let option = document.createElement("option");
  8.       option.value=indice;
  9.       option.innerText=immagine.src;
  10.       dropDownImmagini.appendChild(option);      
  11.     });
  12.     dropDownImmagini.selectedIndex=-1;
  13.     document.body.appendChild(dropDownImmagini);
  14.  
  15.     let etichetta = document.createElement("label");
  16.     etichetta.for = "elencoImmagini";
  17.     etichetta.innerText="SCEGLI UNA IMMAGINE";
  18.     etichetta.style="color:red; font-size: 30; font-weight: bold;";
  19.     dropDownImmagini.before(etichetta);
  20.    
  21.     dropDownImmagini.addEventListener("click", function () {
  22.       eliminaBordi();
  23.       if (this.selectedIndex>=0) immagini[this.value].style.border="5px dashed red";
  24.     });
  25.  
  26.     function eliminaBordi()
  27.     {
  28.       immagini.forEach( (elemento)=> elemento.style.border="");
  29.     }
  30.  
  31.   </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement