href="#" Going to Top of Page - Prevent?

L84 picture L84 · Oct 22, 2012 · Viewed 55.1k times · Source

I have a page with some jQuery functions. The HTML on the page looks like so:

<a href="#" class="service">Open</a>

When I click the Open button a hidden panel slides out. The jQuery itself works great however when I click the button it also takes me to the top of the page.

Is this the defualt behavior and how do I prevent every href="#" from taking me to the top of the page.

Note: I could add id's and tell the href to direct to that ID. I do not want to do that for various reasons (including adding unnecessary code).

Answer

MyroslavN picture MyroslavN · Mar 29, 2016
<a href="#!" class="service">Open</a>