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');
        }                
    });
};
3
  • if ( $(event.target).closest('tbody').length ) {... Commented Jul 28, 2016 at 19:44
  • Had to change it to 'thead in the .closest but it works. thanks! Commented Jul 28, 2016 at 20:12
  • Does this answer your question? Detect click inside/outside of element with single event handler Commented Dec 19, 2019 at 21:22

1 Answer 1

0

Correct syntax below:

if($(event.target).closest('thead').length === 0)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.