How can a do to execute a function when clicking a link? Something like: <p>Link</p> <script> $("p").click(function () { $(this).myFunction(); }); </script> <script> function myFunction( ) </script>
<script> $("#link_id").click(function () { alert("Clicked"); return false; }); </script> This will disable the normal behaviour of the link so if the href is # it will not get you to the top of the page, it won't do anything else than showing the alert box. Even if the href is google.com it won't redirect there.
$(document).ready(function(e) { $(document).delegate("#link_id","click",function(){ if(confirm("Would you like to continue to the link ?")) { return true; } else { //in case you don't want to disable the behaviour of the link e.stopPropagation(); e.preventDefault(); return false; } }); Code (markup): Try the above...