if text is matched then get the parent th in jquery code example Example: get main tr from td jquery tdToPad.closest('tr') .addClass('X-' + pad)