views:

101

answers:

1

I'm trying to use JS to access data in OpenGraph meta tags. It works fine with meta tags that have the standard attributes (name="x" content="y"), but for OpenGraph tags, the meta tag reads

<meta property="x" content="y">

I haven't had any luck accessing the contents of the "property" attribute using JS. The .name attribute is just empty. Any ideas?

+1  A: 

Use getAttribute.

E.g. assuming you have the element in myMeta:

myMeta.getAttribute('property');

There isn't a complete mapping between HTML attributes and DOM properties. As you've seen, some (possibly invalid) don't have JavaScript properties. For others, they exist under a different name. E.g. the class attribute becomes className.

Matthew Flaschen