Hi, I have a function which hides and shows a div. When i click the link to show the the div the page loads at the top. What i want to do is keep the focus on the link. This is what i am using but does not seem to work? function change(which) { document.getElementById('div1').style.display = 'block'; document.getElementById('div1').focus(); } Code (markup): Here is the link: <a href="#" onclick="change('div1');">Click here</a> Code (markup): Any ideas why it is not working?
<a href="#" onclick="change('div1'); return false;">Click here</a> HTML: Just add a return false at the onclick attribute. Or replace the # with javascript:; <a href="javascript:;" onclick="change('div1');">Click here</a> HTML: I think void(0); should work too...