jquery/[removed] function(e){… what is e? why is it needed? what does it actually do/accomplish?

后端 未结 4 1212
既然无缘
既然无缘 2020-11-30 23:48
$(\'#myTable\').click(function(e) {
    var clicked = $(e.target);
    clicked.css(\'background\', \'red\');
});

Can someone explain this to me, an

4条回答
  •  盖世英雄少女心
    2020-12-01 00:21

    It's the formal parameter for the function. jQuery will pass in an event object when the function is called. This is used to determine the target. As noted in the documentation, jQuery will always pass an event object even when the browser (e.g. IE) doesn't.

    In this case, the target tells you which element was originally clicked.

提交回复
热议问题