prev_element

returns an element that is previous.

Source


def prev_element(self):
    if self.has_parent():
        brothers = self._parent.children()
        if isinstance(brothers, pyNodeList) and len(brothers) != 0:
            for i in range(len(brothers)):
                if brothers[i].name() != 'comment':
                    if brothers[i] == self and i != 0:
                        return brothers[i - 1]
    return None