Close Modal with JavaScript

I’m trying to close my modal when add to cart button is clicked.

here is the code for the button to close:

<button class="btn btn-info btn-block addItemBtn" id="closemodal" >&nbsp;Add to cart</button>

here is the javascript code:

          $(document).ready(function() {

            // Send product details in the server
            $(".addItemBtn").click(function(e) {
              e.preventDefault();
              var $form = $(this).closest(".form-submit");
              var pid = $form.find(".pid").val();
              var pname = $form.find(".pname").val();
              var pdesc = $form.find(".pdesc").val();
              var pprice = $form.find(".pprice").val();
              var pcode = $form.find(".pcode").val();
              var pqty = $form.find(".pqty").val();

              $.ajax({
                url: 'action.php',
                method: 'post',
                data: {
                  pid: pid,
                  pname: pname,
                  pdesc: pdesc,
                  pprice: pprice,
                  pqty: pqty,
                  pcode: pcode
                },
                success: function(response) {
                  $("#message").html(response);
                  window.scrollTo(0, 0);
                  load_cart_item_number();
                }
              });
              $('#closemodal').click(function() {
                $('#modalwindow').modal('hide');
              });
            });
         });

When I clicked the add to cart button that I want is added to cart but the modal is still open. I want it to automatically closes when the button is clicked.