0

I have some jQuery that is working just fine in Chrome but when tested it is not working at all. To help troubleshoot it I created a simple button with a very stripped down version of the jQuery that should just show a delete button. However, I'm getting a syntax error in the console and I'm not seeing the alert.

Anyone see what I'm missing? I'm using a CSS class to hook the jQuery code to the button but I don't think that's an issue....unless IE can't handle that.

$(".delete").on('click', (e) => {
  e.preventDefault();

  alert("delete");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<button class="btn btn-danger delete"><i class="fas fa-trash-alt"></i> Delete</button>
Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61
Caverman
  • 3,371
  • 9
  • 59
  • 115

1 Answers1

2

IE11 does not support the arrow notation for anonymous functions. Change (e) => {} to function(e) {} like this:

$(".delete").on('click', function(e) {
    e.preventDefault();

    alert("delete");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<button class="btn btn-danger delete">
    <i class="fas fa-trash-alt"></i> Delete
</button>
Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
  • Bummer....guess I'm back to refactoring code. It will be nice once Microsoft truly gets out of the browser game. – Caverman Dec 11 '18 at 21:27
  • Microsoft will probably never get out of the browser business. But remember that IE is being phased out in favor of their new Edge browser. – Racil Hilan Dec 11 '18 at 21:32