It will depend on when the script is executed. Javascript is executed by the browser as it is encountered, which means that if your snippet of code exists in the page before the HTML element, then at that point in time, the HTML element does not yet exist.
One solution would be to put the Javascript at the very end of the page, or move that code into the document.onload
handler.
document.onload = function () {
show();
};