HTML and CSS Reference
In-Depth Information
<img itemprop="photo" alt="AJ"
cartoons/aj/headshot_aj.gif" >
<span itemprop="email">
<a href="">
You can see the full code in ch05/microdata-api-1a.html. Here are the
results of running the same extraction loop used earlier:
fn: A. J.
n: [object HTMLElement]
The email is fixed, but now there's something wrong with the n value.
It's no longer a simple string, it's an HTMLElement . This is because if an
item has child properties, itemValue doesn't contain a string; instead it
contains another NodeList object. You can loop through that one the
same way as before, but it's easier to define a recursive function:
function getMDProperties(name, props) {
if (name.length > 0) name += '/';
for (var i = 0; i < props.length; i++) {
if (typeof(props[i].itemValue) == 'object') {
} else {
log(name + props.names[i] + ': '
+ props[i].itemValue);
This function is modeled on the loop used before, but it checks to see
whether itemValue is an object. If it is, then the properties of the child
object are passed recursively to the function. The name of the parent
Search WWH ::

Custom Search