Question

Would you advise against reading and using 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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top