How can I avoid .prev().prev().prev() calls? Is there a shortcut for this?
.prev().prev().prev()
You can use .prevAll in combination with eq or :eq , since prevAll returns the set of elements in the reverse order, starting from the element closest to the current element [0] , equivalent to .prev().prev().prev() will be .prevAll().eq(2) or .prevAll(':eq(2)') .
.prevAll
eq
:eq
prevAll
[0]
.prevAll().eq(2)
.prevAll(':eq(2)')
See this simple demo: http://www.jsfiddle.net/QZYHN/
You can do prevAll() with a selector.
prevAll()
$('div').prevAll('a:last')
Try closest , which searches for the closest ancestor that matches the selector. eg.
closest
$(this).closest('table').find('selector')
Edit: Added find () function at the end
take a look at nth-child in jquery, may be useful ...
nth-child