The judgment of the court in cases of contested election, shall confirm or annul the election according to the right of the matter; or, in case the contest is in relation to the election of some person to an office, shall declare as elected the person who shall appear to be duly elected.