Google

def previous_element element = previous_sibling element = element.previous_sibling until element.nil? or element.kind_of? Element return element end