Tuesday 15 February 2011

javascript - How to prevent redirect after hyperlink click? -



javascript - How to prevent redirect after hyperlink click? -

i have next html+ js code:

<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> </head> <body> <a href="#" id=key onclick="func(0)">foo</a> </body> <script type="text/javascript"> function func(k){ alert(1); homecoming false; } </script> </html>

can explain how refactor next code after click on href code func executes # doesn't add together url , page shouldn't reload?

use javascript:void(0); instead of # follows:

<a href="javascript:void(0);" id=key onclick="func(0)">foo</a>

javascript html hyperlink onclick href

No comments:

Post a Comment