HTML5 Guidelines for Web Developers

(coco) #1

270 Chapter 11—Microdata


Starting from the relevant top-level item, we can then work towards the prop-
erties defined with itemprop. We find these in item.properties, the so-called
HTMLPropertiesCollection, which allows access to the name-value pairs of each
property via additional interfaces. The elements are sorted according to their
position in the DOM tree. Table 11.3 shows the required attributes and meth-
ods, and their content.

Table 11.3 Attributes and methods of “HTMLPropertiesCollection”

Attribute/Method Content

length Number of elements in a collection
item(index) Element in a collection at position index

namedItem(name) Collection consisting of the elements whose
itemprop attribute has the value name
namedItem(name).values Array with the contents of all itemprop attributes
whose value is name

names DOMStringList of all itemprop attribute values in
the collection
names.length Number of itemprop attribute values

names.item(index) Name of itemprop attribute value at position
index
names.contains(name) Boolean attribute for testing if the string name is
present as an itemprop attribute value

The last attribute in the microdata DOM API is itemValue. It allows access to the
content of elements that have an itemprop attribute. If an element in a variable
elem is a container—for example, article, div, or span—then elem.itemValue
represents the text content that can also be changed.
You need to be careful if nested items are involved, because then the element
concerned also has an itemscope attribute and the content of the element has to
be interpreted independently, almost as a top-level item. The specification takes
this into account and requires that in this case elem.itemValue makes a new item
object available.
A second and last special case concerns HTML elements, which you have already
encountered as elements with special status in the section on itemprop attributes.
a, src, time, meta, and object belong to this category and assign their href, src,
datetime, content, or data attribute to elem.itemValue, in contrast to the usual
practice. The list of all representatives in this category are found in Table 11.1.
Free download pdf