What if both husband an wife are on the title but not the mortgage and they get divorced?

The person who is on the mortgage is legally responsible for paying the debt. If the debt is not paid the bank will take possession of the property. The division of the property will be addressed through negotiation by the attorneys representing the parties or by a judicial order.