if(self.href != "#")
There's your problem. Link hrefs are canonicalised by the browser, so a link ‘#’ on page ‘http://www.example.com/’ has an href attribute of ‘http://www.example.com/#’ and does not match the condition.
Avoid using the name ‘self’, as it clashes with the name of the global object (aka ‘window’). You can avoid the clumsy passing in of ‘self’ by assigning the handler from JavaScript:
document.getElementById('load').onclick= request;
instead of the onclick
attribute, then you could use ‘this’ in request(). request() should also return false;
to stop the link being followed (making the browser scroll to the top). Better still would be to use a <button>
(or <input type="button">
), because it's an action button and not a link that you could open in a new window or bookmark. (You can always use CSS to make it look less like a button.)
Don't use setAttribute() for HTML, it has problems in IE unrelated to this usage. Setting element.id
was already fine.
But this all seems like rather a strange way of going about what you want to do in any case.