Angular ng-click $event passes child element as target

后端 未结 3 2043
故里飘歌
故里飘歌 2021-02-19 10:06

For each td element in a table I have an attached ng-click. Here is the (simplified) html for each table cell:



        
3条回答
  •  执笔经年
    2021-02-19 10:41

    event.target.closest('td') won't work because event.target is a DOM element and it doesn't have method closest. You need to create a jQuery object to use this method.

    Try to find closest td like this:

    angular.element(event.target).closest('td')
    

提交回复
热议问题