Advertisement
1xptolevitico69

Javascript create element Image

Jan 18th, 2022
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.07 KB | None | 0 0
  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>Javascript create element Image</title>
  8.     <style>
  9.  
  10.      div {
  11.         padding: 5px;
  12.         width: 500px;
  13.         border: 5px solid red;
  14.         margin: auto;
  15.     }
  16.      
  17.        .title {
  18.         margin: 0;
  19.         text-align: center;
  20.         font-family: verdana;
  21.         font-weight: 900;
  22.         font-size: 30px;
  23.        }
  24.  
  25.       #pic {
  26.         width: 100%;
  27.     }
  28.  
  29.  
  30. </style>
  31. </head>
  32. <body>
  33.  
  34.       <div id='box'></div>
  35.  
  36.  
  37.   <script>
  38.     txt = 'IMAGE';
  39.  
  40.     image = document.createElement('img');
  41.     sub = document.createElement('p');
  42.     sub.className = 'title';
  43.     box.appendChild(image);
  44.     box.appendChild(sub);
  45.     image.id = 'pic';
  46.     sub.innerHTML = txt;
  47.     image.title = 'Javascript create element image';
  48.     image.className = 'img';
  49.     image.src = 'https://1xpto.netlify.app/pics/blue.jpg';
  50.  
  51.  
  52. </script>
  53. </body>
  54. </html>
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement