开发者

Okay to use the hash DOM node property?

Would you advise against reading and us开发者_JAVA技巧ing the hash DOM node property? (Do you think it might be deprecated and removed in the future?)

What is it? For a link <a href='http://server/folder/page#the-hash'>, the value of the hash property is #the-hash. It seems to be present in all browsers, see the JavaScript Bible page 603, and I've tested Safari, Chrome, FF and IE and Opera.

Background: I use jQuery, but in IE 7 this: $(elem).attr('href'); doesn't return the href attribute, but rather the href prefixed with server address and the path to the page. Example: if the href is #the-hash then attr returns http://server/folder/page#the-hash in IE 7. Here is a jsfiddle example.


If you stay away from every feature, API, etc that might possibly be deprecated sometime in the distant future, you'll never get anything done. They could deprecate alert tomorrow, or for...in (far more likely, but eh. that's beside the point.)

Worry about what's deprecated now. And location.hash is not. It's a full-fledged member of the HTML5 DOM, and will be for the foreseeable future. If it ever does end up deprecated, it'll probably still be supported for ages after, as a "living standard" (which is what HTML has allegedly become) makes things exceedingly hard to deprecate and/or remove.

Either way, if you want to change it later, you can.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜