That way if I change the html structure I don't have to to change a million jquery selectors, I can just change the from function in one place.
// Access one particular element from another.
function from(start, end) {
start = $(start)
if(start.parent().hasClass('headline') && end == 'node')
return start.parent().parent()
if(end == 'nodes') return start.children('.node')
if(end == 'headline') return start.children('.headline')
if(end.indexOf('.') != 0) end = '.' + end
if(start.hasClass('headline')) return $(start.children(end))
return start.find('> .headline > ' + end)
}
(I'm still somewhat new to Javascript, so this may be a well-known pattern.)