Get the App
SLTechnology News&Howtos  ›  Development  › 

Is id unique in html documents?

Shulou Source: shulou.com Published: 2022-06-02 06:49:29 10月04日 Update

This article mainly explains the "html document in the id is unique", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in-depth, together to study and learn "html document id is the only" it!

Id must be unique in the HTML document. In the HTML document, any element (node) has an id attribute, and the id attribute is the unique identification of the node, which is the "unique" identifier when specifying the DOM operation for a node, so the id value in the same document cannot be repeated; if it is not a unique identifier, it will bring trouble to the DOM operation.

The operating environment of this tutorial: windows7 system, HTML5 version, Dell G3 computer.

The id attribute specifies the unique id of the HTML element.

Id must be unique in the HTML document.

In a HTML document, any element (node) has an id attribute, and the id attribute is the unique identity of the node and the "unique" identifier when specifying the DOM operation for a node, so the id value cannot be repeated in the same document.

ID has nothing to do with how the page is rendered, but whether it is rendered correctly depends on the structure and style of the document (here is the browser's default style sheet + a style rule you wrote), so it can be displayed normally.

However, it is not the only identifier that can cause trouble for DOM operation.

# txtName {background:red;} function GetValue () {var a = document.getElementById ('txtName'). Value;alert (a);} name: password:

Tags: Documents nodes attributes identifiers elements identifiers styles learning content tags browsers trouble browsing just name password that is ideas situations effects Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Docker Apple MariaDB Linux