abbottjam abbottjam - 1 year ago 62
HTML Question

Using Microdata's 'itemprop' attribute on non-text elements

I have a following piece of HTML with some Microdata added:

<section class="feature" itemprop="description">
<div class="measure">
<p>Lorem ipsum etc...</p>
<p>Lorem ipsum etc...</p>

<figure class="polaroid product">
<img src="dry-aged-beef-horizontal.jpg", alt="Dry Aged Beef", itemprop="image" />
<figcaption>Dry Aged Beef</figcaption>

Is it all right to use the
attribute on an element that isn't itself a text node (like
above), but contains child elements that are?

Looking at the official examples one could become suspicious that only text elements can be tagged with Microdata attributes:

<span itemprop="description">0.7 cubic feet countertop microwave. Has six preset cooking categories and convenience features like Add-A-Minute and Child Lock.</span>

Also, my product description consists of more paragraphs than one, so again setting the
tag on a parent element makes all the sense. Is this correct Microdata/ though?

Answer Source

Microdata (W3C Note) defines that the property value is, in the general case (which applies in your example):

[…] the element's textContent.

So yes, your usage is fine.

(Of course this means that "Dry Aged Beef" will also be part of the description value.)