You might need "after" == element.tag_name.