Stop event with event.preventDefault() - Javascript DOM

Javascript examples for DOM:Event


Stop event with event.preventDefault()

Demo Code

ResultView the demo in separate window

      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <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);


Related Tutorials