Uncaught TypeError: Cannot read property 'ownerDocument' of undefined

前端 未结 6 1220
生来不讨喜
生来不讨喜 2020-12-29 01:57

I\'m teaching myself AJAX to AJAXify my site. In my template, I have the following JS code to get some JSON data from a view then append the data to a div.

f         


        
6条回答
  •  梦谈多话
    2020-12-29 02:14

    If you use ES6 anon functions, it will conflict with $(this)

    This works:

    $('.dna-list').on('click', '.card', function(e) {
      console.log($(this));
    });
    

    This doesn't work:

    $('.dna-list').on('click', '.card', (e) => {
      console.log($(this));
    });
    

提交回复
热议问题