$(document).ready(function () { 'use strict'; $('#selected-plays > li').addClass('horizontal'); $('#selected-plays li:not(.horizontal)').addClass('sub-level'); $('a[href^="mailto:"]').addClass('mailto'); $('a[href$=".pdf"]').addClass('pdflink'); $('a[href^="http"][href*="henry"]').addClass('henrylink'); $('tr:nth-child(odd)').addClass('alt'); $('a').filter(function () { return this.hostname && this.hostname != location.hostname; }).addClass('external'); // $('td:contains(Henry)').nextAll().addBack().addClass('highlight'); // $('td:contains(Henry)').parent().children().addClass('highlight'); $('td:contains(Henry)') // Find every cell containing "Henry" .parent() // Select its parent .find('td:eq(1)') // Find the 2nd descendant cell .addClass('highlight') // Add the "highlight" class .end() // Finish current filtering, return to previous state: the result of parent() .find('td:eq(2)') // Find the 3rd descendant cell .addClass('highlight'); // Add the "highlight" class $('#selected-plays > li').find('li').addClass('special'); $('tr').find('td:eq(2)').addClass('year'); $($('td:contains(Tragedy)')[0]).parent().addClass('special'); // Would there be a way with has() ? $('li>a').parent().next().addClass('afterlink'); $('a[href$=".pdf"]').closest('ul').addClass('tragedy'); }); // Function end() does not empty the stack, but returns the second-topmost element.