In an action to recover the possession of personal property, judgment for the plaintiff may be for the possession or value thereof, in case a delivery cannot be had, and damages for the detention. If the property has been delivered to the plaintiff, and the defendant claim a return thereof, judgment for the defendant may be for a return of the property, or the value thereof, in case a return cannot be had, and damages for taking and withholding the same.