Add Unique ID for an Element in HTML



Use the id attribute in HTML to add the unique id of an element.

Example

You can try to run the following code to implement id attribute −

<html>
   <body>
      <h1>Tutorialspoint</h1>
      <p id = "myid">We provide Tutorials!</p>
      <button onclick = "display()">More...</button>

      <script>
         function display() {
            document.getElementById("myid").innerHTML = "We provide learning videos as well";
         }
      </script>
   </body>
</html>
Updated on: 2020-06-24T08:28:45+05:30

886 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements