How to fix the "return not in function" error that is shown on firebug?

I am trying to prevent the page from reloading when the user clicks the link, so I wrote:

<a href="javascript: return false">bla</a>

or

<a href="#">bla</a>

Seriously, I don’t like to use it #, because when the user clicks on the link, the url is added with a # character on the address bar, this makes the URL ugly. Therefore, I prefer to use javascript: return false, but firebug show error: "return not in function", can I find out how to fix the error?

+3
source share
3 answers

See this discussion: What & href "value I should use for JavaScript links," "or" javascript: void (0) "?

href="#". , "javascript:;" "javascript:void(0);"

+4

:

<a href="javascript:;">bla</a>

, .

0

Take a look at this ( jsfiddle here ):

<a href="http://www.google.com/" onclick="return false;">click me</a>

However, you should avoid using inline JavaScript. JS in one place, separated from the code, has a higher maintainability.

0
source

All Articles