Advertisement
fcamuso

Javascript Lezione 48

Jun 13th, 2022
1,377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.80 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="IT-it">
  3. <head>
  4.     <title>DOM1</title>
  5.     <style>
  6.         img {width: 50px; height: 50px;}
  7.     </style>
  8. </head>
  9. <body>
  10.     <div id='div1'>
  11.         <p id="p1">primo paragrafo</p>
  12.         <p id="p2">secondo paragrafo
  13.                    <img id="img1" src="teatro.png" alt="Locandina Teatro">
  14.         </p>
  15.     </div>
  16.  
  17.     <div id='div2'>
  18.         <a href="https://www.bbc.com">sito bbc</a>
  19.     </div>
  20.  
  21.     <script>
  22.         //RESTITUISCONO UN SOLO OGGETTO
  23.         //getElementById('questo_id') -> oggetto con quell'id
  24.         //querySelector('pattern_ricerca_alla_CSS') -> il primo che soddisfa il pattern
  25.  
  26.         //testo rosso e dimensione carattere 35px al testo del paragrafo id='p1'
  27.  
  28.         const par_p1 = document.getElementById('p1');
  29.        
  30.         //if (par_p1!==null){
  31.         if (!par_p1){ // "", '', undefined, false, NaN
  32.             //gestione errore
  33.         }
  34.         else
  35.         {
  36.             //  .style agisce  sugli stili IN LINEA
  37.             par_p1.style.fontSize = '2em';
  38.             par_p1.style.color = '#0000ff';            
  39.         }
  40.  
  41.         const img1 = document.getElementById('img1');
  42.  
  43.         //getComputedStyle tiene conto di TUTTI gli stili
  44.         const stili_img1 = window.getComputedStyle(img1);
  45.        
  46.         const widthAttuale = parseInt(stili_img1.width); //da 50px al numero 50
  47.         const heightAttuale = parseInt(stili_img1.height);
  48.  
  49.         img1.style.width = widthAttuale*2+"px";
  50.         img1.style.height = heightAttuale*2+"px";
  51.  
  52.  
  53.         //RESTITUISCONO UN INSIEME DI OGGETTI
  54.         //getElementsByName('questo_name')
  55.         //getElementsByTagName('questo_tag')
  56.         //getElementsByClassName('questa_classe')
  57.         //querySelectorAll('pattern_ricerca_alla_CSS')
  58.  
  59.     </script>
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement