envjs / env-js

A pure-JavaScript browser environment.
http://www.envjs.com/
87 stars 19 forks source link

HTMLAnchorTag doesn't support a.hash #36

Open kennardconsulting opened 8 years ago

kennardconsulting commented 8 years ago

I get the feeling this project is long since abandoned, but I'll leave this here for what it's worth. It was a great project, BTW!

Env.js 1.2 doesn't support a.hash. That is, if you create an anchor tag, with an href, and then try to look it up via a.hash, it returns undefined. This code fixes that (albeit crudely):

HTMLElement.prototype.setAttribute = function(name, value) {
    //console.log("CSS set attribute: " + name + ", " + value);
    origSetAttribute.apply(this, arguments);
    if (name === "style") {
        updateCss2Props(this, value);
    }
    // Add support for 'HTMLAnchorTag.hash'
    if (this.tagName === "A" && name === "href" && value.indexOf( "#" ) !== -1 ) {
        this.hash = value.substring( value.indexOf( "#" ));
    }
}