Element.id
A propriedade Element.id
representa o identificador do elemento, refletindo no atributo global id.
O ID precisa ser único no documento, e geralmente é utilizado para obter o elemento usando getElementById
.. Outro uso comum de id
é utilizar o ID como um seletor ao estilizar o documento com CSS.
Nota: IDs são case-sensitive, mas você não deve criar IDs cuja única diferença nos nomes sejam letras maiúsculas/minúsculas (veja Case sensitivity in class and id names).
Sintaxe
var idStr = element.id; // Retorna o id. element.id = idStr; // Insere o id
idStr
é o identificador do elemento.
Especificações
Especificação | Status | Comentário |
---|---|---|
DOM The definition of 'id' in that specification. |
Padrão em tempo real | Sem alteração desde Document Object Model (DOM) Level 2 HTML Specification. |
Document Object Model (DOM) Level 2 HTML Specification The definition of 'id' in that specification. |
Obsoleto | Sem alteração desde Document Object Model (DOM) Level 1 Specification. |
Document Object Model (DOM) Level 1 Specification The definition of 'id' in that specification. |
Obsoleto | Definição inicial. |
Compatibilidade com navegadores
BCD tables only load in the browser
Veja também
- O atributo global id.