It is not a matter of prevailing. What happens when you click on link is that it is fired in event. This event only calls a code that must execute what the programmer wants. In case the event is called onclick
and is associating with a href
. The code can do whatever it wants there. In case it does nothing.
It was defined in the specification (I believe) that this code would define whether the normal click action would still be executed or not based on the return of a boolean provided by this code executed by the event. So if the code returns a true
(if I am not mistaken do not need to return something specific for the normal action to occur) the normal action is still executed after the action of this code, but returning false
the normal action is deleted. It is considered that everything that should be done is already done by the code.
It is a useful convention established to give more flexibility. It is only a simple decision that is made by engine based on pre-established rules. Imagine how difficult it would be to perform certain tasks if the link "function" always after you do an action. Eventually you would have repeat action or conflicting actions.
Example:
<a href="http://www.pt.stackoverflow.com/" onclick="return (confirm('Pode seguir o link?'))">SOpt</a>
I put in the Github for future reference.
Today it is possible to use something more modern as the Event.preventDefault.
Interesting article on the subject (in English): http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/
– Pablo Almeida