I'm trying to highlight the parent tr
of a table, if a children td > p
has a certain class. I have the following:
$(document).ready(function(){
var $target = $('.flag-wrapper p').closest("tr");
var $element = $('.flag-wrapper p').hasClass("selector-on");
if ( $element ) {
$target.addClass("marked-row");
} else {
// whatsoever
}
});
Now my problem is that I can't target just the current tr. I've tried using $(this) but as far as I can tell it won't work inside the if statement.
Any insights on how should I proceed with this would be much appreciated. Also, I guess it would be easier to work with a .click() event but I have to check this .hasClass() on page load instead of user action.