id / name
The attribute
id
is used to
uniquely identify a HTML element. The value of the
id
attribute can be used in
JavaScript to get the corresponding Node object:
var node = document.getElementById('the-id');
The attribute name
is similar, but the same value can be assigned to multiple HTML tags. Thus, name
does not uniquely identify a HTML element. Accordingly, the corresponding function to query for elements with a specific name value is plural and returns an array:
var nodes = document.getElementsByName('…');
data
A
data-…="…"
attribute allows to associate
data with an element.
Data atttribute values are considered private to a page and should (unlike Microformats) not be indexed by
search engines.
Compare with itemscope
and itemtype