For getting stability.
every atom has 0 charge. Due to transfer of elections body get changed due to excess of electron there will be positive charge and due to lack of electron there will be negative charges so two body want to neutralise their charges for stability so opposite charges attracts each other and similar or like charges repel each other.