开发者

Does Element.getAttribute() work in IE7 with unknown-to-IE attributes?

开发者 https://www.devze.com 2023-01-27 04:06 出处:网络
I\'m trying to add event rich snippets to my site so that Google can know about the events. Then, leading to the cause of my question, I want to use the time data to do some various Javascript operati

I'm trying to add event rich snippets to my site so that Google can know about the events. Then, leading to the cause of my question, I want to use the time data to do some various Javascript operations. I am usi开发者_Python百科ng the microdata approach Google outlines in the first link, but I am using span elements instead of time ones, since IE 7 (and 8) will treat the unknown time element as an inline element and I'd rather not use the HTML5 shiv if not absolutely necessary.

I am able to retrieve all the appropriate time spans (using jQuery("span[itemprop=startDate]")). However, in IE7 (and not in IE8 or FF or the WebKit-based browsers) I cannot get the 'datetime' attribute that I know each span has. It doesn't matter whether I use the native getAttribute() method or jQuery's attr(), I always get null back.

Any idea why and how I can work around this? Thanks!

Update: I have added a simple example. In Chrome I get alert that say 'datetime via DOM methods is: 2010-11-25' and 'datetime jQuery is: 2010-11-25' but in IE7 I get 'datetime via DOM methods is: null' and 'datetime via jQuery is: undefined'.


It does, at least for div and b elements. Oddly it doesn't seem to with a span. So, try using div instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消