Get the id of the first anchor:
let id = document.getElementsByTagName("a")[0].id;
Try it Yourself »
Change the id of an element:
document.getElementById("demo").id = "newid";
Try it Yourself »
Change the font size of "myP":
const element = document.getElementById("myP");
element.style.fontSize = "30px";
Try it Yourself »
The id
property sets or returns the value of an element's id attribute.
An id should be unique within a page.
Return the id property:
element.id
Set the id property:
element.id =
id
Value | Description |
id | The id of the element. |
Type | Description |
String | The id of the element. |
element.id
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!