I am working on a large website (1600+ pages) that needs upgrading to pass standards compliance. As a result, for every OnClick there has to be, say the Standards, an OnKeyPress handler, so that people not using a mouse can still access the content.
Some tags have an onclick javascript handler. EG:
<a onclick="doSumat();">
Is the following cross browser, working javascript:
<a onclick="doSumat();" onkeypress="this.onclick();" >
Will it work reliably in all browsers and will the result be the same as a mouse click for someone using a screen reader?
In this case, why not call
doSumat();with both the onclick and onkeypress handlers?If you need a
thiscontext, then you’ll need to usedoSumat.call(this);, but you can still place that in both handlers.With 1600 pages, I imagine you’re trying to find something simple to append to every element with an
onclickhandler, but shouldn’t be that much more complex to define rules to blindly copy everything from anonclickstatement to anonkeypressexpression.