If the defendant, at any time before the trial, offer in writing to allow judgment to be taken against him or her for a specified sum, the plaintiff may immediately have judgment therefor, with costs then accrued; but if he or she do not accept such offer before the trial, and fail to recover on the trial of the action, a sum greater than the offer, such plaintiff shall not recover any costs that may accrue after he or she shall have been notified of the offer of the defendant, but such costs shall be adjudged against him or her, and if he or she recover, deducted from his or her recovery. But the offer and failure to accept it, shall not be given in evidence to affect the recovery, otherwise than as to costs, as above provided.