Forum Moderators: open
First post here - just hoping to utilize someone's knowledge with javascript / css.
I am currenty showing/hiding several divs on the same page using javascript and css. Once executed however (onClick), the divs being hidden/shown further down the page cause the page to reset to the very top (not showing the content that was shown/hidden).
Is anyone aware of a way to keep the page at the same place once a link is clicked executing a javascript code?
Any help is greatly appreciated.
Thanks so much,
Scott
<a href="#" onclick="showHide();">
That will call the function showHide then follow the link, which is #
Change it to this
<a href="#" onclick="showHide(); return false">
Now it calls the function and stops, doesn't follow the link.
If I'm completely wrong, you're going to need to post some exmaple code.
<a href="#" onclick="showhidemethod();">...</a>
In the above case, you want to return false to your onclick handler:
<a href="#" onclick="showhidemethod(); return false;">...</a>
That will prevent the link from processing the href link.
A better solution would be to use unobtrusive JavaScript to attach an event listener, and to have that listener stop the event propagation. In other words, you keep your markup clean and free of any scripting and your script will attach listeners to your elements.
[edit]Trace beat me to the punch, and my post is pretty much a duplicate of what Trace said. :-)[/edit]
[edited by: Fotiman at 6:11 pm (utc) on Aug. 8, 2008]