TypeError: document.getElementById(...).getElementsByTagName(...).click is not a function
<p><a href="https://stackoverflow.com/questions/36752813/listening-to-the-keypressed-event-razor/36753358#36753358">Origin source</a></p>

<pre><code>&lt;script&gt;
    document.addEventListener('keydown', function (e) {
        // 37 is left arrow, 39 is right arrow
        if (e.which === 37) {
            document.getElementById('previousPhoto').getElementsByTagName('a').click();
        } else if (e.which === 39) {
            document.getElementById('nextPhoto').getElementsByTagName('a').click();
        }
    });
&lt;/script&gt;
</code></pre>

<p>generates an error which I put on the title above. </p>

<p>P.S. There are those links. Working perfectly when I mouse-click. </p>