Javascript examples for DOM:Event
Stop event with event.preventDefault()
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <a href="delete.php?id=22" class="confirmation">Link</a> <script type="text/javascript"> var elems = document.getElementsByClassName('confirmation'); var confirmIt = function (e) { if (!confirm('Are you sure?')) e.preventDefault();//from ww w . j a v a 2 s . c o m }; for (var i = 0, l = elems.length; i < l; i++) { elems[i].addEventListener('click', confirmIt, false); } </script> </body> </html>