Search code examples
javascriptjqueryinternet-explorer-11

Simple jQuery click event not working in IE11?


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>


Solution

  • 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>