Sean_Dewlin's solution didn't work **only** because the bit about returning false was missed.
when I add a real URL the page will have to refresh to get the content instead of just hiding or showing a div?
No. You can still have the hidden content "in the page," but the alternate content is an expanded version similar to the content in the div.
Scenario:
<a href="some-alternate-content.html">test</a>
Following that link (note I didn't say "click" :-) ) will load the page some-alternate-content.html.
<a href="some-alternate-content.html" onclick="somefunction();">test</a>
Following that link will execute the Javascript function somefunction, but it will simultaneously navigate the the page. To avoid this, many coders will do things like this:
<a href="javascript:somefunction();">test</a>
<a href="javascript:void();" onclick="somefunction();">test</a>
<a href="#" onclick="somefunction();">test</a> <!-- navigates to page top, but doesn't leave page -->
All of these "work." What they DON'T do is consider a larger picture, which involves the overall health of your page.
- Javascript disabled or a client that doesn't execute Javascript: Your visitor gets nothing at all following these links.
- Decreased site content: a search engine can't follow these links, they don't go anywhere. You're missing an opportunity to provide more content to them.
- Decreased links: given the above, your site now has less internal linking.
However, this
<a href="some-alternate-content.html" onclick="somefunction();
return false;">test</a>
or this
<a href="some-alternate-content.html" onclick="
return somefunction();">test</a> <!-- as above, return false from the function itself -->
Solves all three issues. Returning false from any "natural" navigation object (works on forms too) prevents the browser from executing the normal action. As anything that is well built, it requires a little more work, but it's worth it.