I try to prevent page reload when user click a link, so I wrote :
<a href="javascript: return false">bla</a>
Or
<a href="#">bla</a>
Seriously I don't like to use #
because when user click on the link, the url on the address bar is added the symbol #, it make the url look ugly. So I prefer to use javascript: return false
but firebug show error : "return not in function", may I know how to fix the error?
I try to prevent page reload when user click a link, so I wrote :
<a href="javascript: return false">bla</a>
Or
<a href="#">bla</a>
Seriously I don't like to use #
because when user click on the link, the url on the address bar is added the symbol #, it make the url look ugly. So I prefer to use javascript: return false
but firebug show error : "return not in function", may I know how to fix the error?
- :-) not exactly. on clicking the link nothing will happen then why he need the href!!! i was inspired by sprynos answer :-) – zod Commented Jun 1, 2011 at 1:15
- lol. Very creative, but I need onclick attribute. – zac1987 Commented Jun 1, 2011 at 1:25
3 Answers
Reset to default 6See this discussion: Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?
Do not use href="#"
. If it has to be, either use "javascript:;"
or "javascript:void(0);"
Try using this instead:
<a href="javascript:;">bla</a>
Hope that helps.
Look at this (jsfiddle here):
<a href="http://www.google./" onclick="return false;">click me</a>
However, you should avoid using inline JavaScript. The JS in one place, separated from the code, has higher maintainability.