Advertisement
root1024

Select an Element By ID

Feb 19th, 2023
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.96 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  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.  
  11. <body>
  12.     <h1>select an Element By ID</h1>
  13.     <ul>
  14.         <li>List 1</li>
  15.         <li id="second">List 2</li>
  16.         <li>List 3</li>
  17.         <li>List 4</li>
  18.         <li>List 5</li>
  19.     </ul>
  20.     <script>
  21.         let elm = document.getElementById("second");
  22.         console.log(elm);   // this stores an element as a object, it returns <li id="second">List 2</li>
  23.         console.log(elm.innerHTML);        // this return the value store by an object  "List 2" // this method is used to get value
  24.         elm.innerHTML = "<p>List Modified</p>";       // this method is used to set the value of an object
  25.         // console.log("This value is After Modifying : " + elm.innerHTML);
  26.     </script>
  27. </body>
  28.  
  29. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement