Javascript examples for DOM:Element id
The id property sets or gets the id of an element from id attribute.
Set the id property with the following Values
Value | Description |
---|---|
id | Sets the id of an element |
A String, representing the ID of an element
The following code shows how to get the id of an element:
<!DOCTYPE html> <html> <head> </head>// ww w . j av a 2s.c om <body> <div id="myDIV"> I am a DIV element </div> <button onclick="myFunction()">Test</button> <script> function myFunction() { var x = document.getElementsByTagName("DIV")[0]; if (x.id === "myDIV") { x.style.fontSize = "30px"; } } </script> </body> </html>