Edit in JSFiddle

$("#myModal").modal("show");
$(".openModal2").on("click", function(){
	$("#myModal2").modal("show");
  $("#myModal").modal("hide");
});

$(".openModal1").on("click", function(){
	$("#myModal2").modal("hide");
  $("#myModal").modal("show");
})
<!-- 
  Bootstrap docs: https://getbootstrap.com/docs
-->

 <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        <div class="modal-body">
          <button type="button" class="btn btn-default openModal2">Open Next Modal</button>
        </div>
        <div class="modal-footer">
        </div>
      </div>
      
    </div>
  </div>
  
  <!--Modal 2 -->
  
  <div class="modal fade" id="myModal2" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        <div class="modal-body">
          <button type="button" class="btn btn-default openModal1">Open Previous Modal</button>
        </div>
        <div class="modal-footer">
        </div>
      </div>
      
    </div>
  </div>