0

I thought "this" is only for owner of the object but in this code I can't see an object. So what is "this" in this code?

$(function(){
  let $list, $taskForm;
  $list = $('ul');
  $taskForm = $('#taskForm');
  
  $taskForm.on('submit', function(e){
    e.preventDefault();
    let value = $('input:text').val();
    $list.append('<li>' + value + '<li>');
    $('input:text').val('');
    $('li').css('cursor','pointer').hover;
        
  });
  
  $list.on('click', 'li', function(){
    let $this = $(this);
    $this.css('text-decoration', 'line-through').fadeOut(1000);
   
  });
  
});```
  • 1
    The value for `this` is determined at call time, so it's definitely not static. It can be changed from the object the function was defined on ([and often is](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback/)). For listeners, the value of `this` would be the element where the event was triggered. – VLAZ Jan 12 '21 at 10:08

0 Answers0