How to use Id Attribute in HTML5

In this article I am going to explain about Id attribute.
  • 1917

Id Attribute in HTML5

The id attribute use for identify unique id for any HTML element. After defined id we can use this element by id. The id also used in style sheet for point to style sheet.

Browser that supports id Attribute

Internet explorer, Mozilla firefox, Google chrome, opera and Safari browsers.

Syntax

<ElementName id="idName">

Example

In this example "Hello" message will be display after clicking on button message will be change.

 <html>

<head>

<script type="text/javascript">

    function myfun() {

        document.getElementById("htp").innerHTML = "Hello Friend";

    }

</script>

</head>

 

<body>

 

<h1 id="htp">Hello</h1>

<button onclick="myfun()">click me</button>

 

</body>

</html>

Output

idattribute.jpg

Further Readings

You may also want to read these related articles: here
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 
© 2019 DotNetHeaven. All rights reserved.