Ad

Is There A Way To Have Markup As The Value To Schema.org Itemprop?

Is there a way to have markup as the value to a schema.org itemprop node? E.g. this works:

<div itemscope itemtype ="http://schema.org/Movie">
  <h1 itemprop="name">Avatar</h1>
  <span>Director: <span itemprop="director">James Cameron</span> (born August 16, 1954)</span>
  <span itemprop="genre">Science fiction</span>
  <a target="_blank" rel="nofollow noreferrer" href="../movies/avatar-theatrical-trailer.html" itemprop="trailer">Trailer</a>
</div>

But can you make this work:

<div itemscope itemtype ="http://schema.org/Movie">
  <h1 itemprop="name">Avatar</h1>
  <span>Director: <span itemprop="director">James Cameron</span> (born August 16, 1954)</span>
  <span itemprop="genre"> <p>Science</p> <h2>fiction</h2></span>      <<====
  <a target="_blank" rel="nofollow noreferrer" href="../movies/avatar-theatrical-trailer.html" itemprop="trailer">Trailer</a>
</div>
Ad

Answer

The HTML spec defines what the property value is of an element with an itemscope attribute, and it says for elements other than meta, audio, embed, iframe, img, source, track, video, a, area, link, object, data, meter, or time, “The value is the element's textContent“.

So the HTML spec requires consumers of microdata markup to ignore markup inside the span element in <span itemprop="genre"> <p>Science</p> <h2>fiction… and just use the text.

Ad
source: stackoverflow.com
Ad