add class to parent element if conditions are true
addclass, css, javascript, jquery, parent
Solution
$('td', '#the_table > table').each(function() {
if ($(this).text() === '0') {
$(this).parents("tr").addClass("hidden");
}
});
FIDDLE
Problem
I am trying to apply a class to a child's parent element if the conditions are true but cannot seem to get it to work. In short, I want to check a table for a cell that is the number "0" and hide its parent row. I have created a basic jsfiddle of what I have done: http://jsfiddle.net/immbudden/YbZPE/3/ And the snippet of jquery that I have put together: ``` if ($('#the_table>table>td:contains("0")').length === 1) { $(this).parent("tr").addClass("hidden"); } ``` I am still learning jQuery and javascript and this is probably something small, but I can't seem to put my finger on it! Any help would be much obliged, thanks in advance!