It actually is hiding the element, but it's also following your anchor right after (to nowhere). You can return false, or a falsy value. I'd wrap it in void
which will return undefined, but either will work. Here's your codepen and the code: http://codepen.io/anon/pen/dsgKk
<a href="javascript:void(function(){ var a = document.getElementById('hideme'); a.style.display='none'; })();">Click me to hide the div.</a>
(This would also work, but is less clean, imo):
<a href="javascript:var a=document.getElementById('hideme'); a.style.display='none'; return false;">Click me to hide the div.</a>