Anchor HTML tag with onclick Javascript event

When using Google, I found that they use onclick events in anchor tags.

In the option more in the google header, it looks like a regular tag, but onclicking it does not redirect, but opens a menu. Usually when using

<a href='more.php' onclick='show_more_menu()'>More >>></a> 

It usually goes into "more.php" without running show_more_menu() , but I have a menu on this page. How to do, for example google ?

+48
javascript hyperlink anchor onclick
Sep 08 '11 at 12:11
source share
3 answers

If the onclick function returns false, the default browser behavior is canceled. In this way:

 <a href='http://www.google.com' onclick='return check()'>check</a> <script type='text/javascript'> function check() { return false; } </script> 

In any case, whether it does google or not, it does not really matter. It is cleaner to bind your onclick functions in javascript - this way you separate your HTML from other code.

+73
Sep 08 '11 at 12:13
source share

You can even try the option below:

 <a href="javascript:show_more_menu();">More >>></a> 
+38
Oct 05 '12 at 17:27
source share

From what I understand, you do not want to redirect when the link is clicked. You can do:

 <a href='javascript:;' onclick='show_more_menu();'>More ></a> 
+31
Sep 08 '11 at 12:16
source share



All Articles