0

I've been at this for awhile now with no luck so I thought I'd throw something up on SO.

I need the function of a click event in and Angular directive to execute only if the source comes from the tbody not the thead. I've tried a number of routes to get this information, but I can't seem to get the syntax right.

Any help/guidance would be greatly appreciated. Here is my latest/best attempt. Will give you and idea what I'm going for:

/* Linker for the directive */
var linker = function (scope, elm, attrs) {  
    window.setTimeout(function(){
        elm.find('table tbody tr.uib-weeks td button span.text-info').closest('tr').find('button').addClass('chosenReportWeek');
    }, 1000); // This is a hack until we can find the proper load/render event           

    elm.on('click', function(event) {
        if(event.target.parent.indexOf('thead') === -1){
            elm.find('table tbody tr.uib-weeks button.active').closest('tr').find('button').addClass('chosenReportWeek');
        }                
    });
};
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
NealR
  • 10,189
  • 61
  • 159
  • 299
  • `if ( $(event.target).closest('tbody').length ) {...` – adeneo Jul 28 '16 at 19:44
  • Had to change it to `'thead` in the `.closest` but it works. thanks! – NealR Jul 28 '16 at 20:12
  • Does this answer your question? [Detect click inside/outside of element with single event handler](https://stackoverflow.com/questions/4660633/detect-click-inside-outside-of-element-with-single-event-handler) – Heretic Monkey Dec 19 '19 at 21:22

1 Answers1

0

Correct syntax below:

if($(event.target).closest('thead').length === 0)
NealR
  • 10,189
  • 61
  • 159
  • 299