How to show an error or success message after clicking on the button by Jquery

Please use the below Jquery for the show message after submitting and on the click buttonHow to show error or success message after clicking on the button by Jquery

<script>
    require(['jquery'],function ($) {
     $('.custom_button').click(function() {
     var email = $('form.subscribe input[name="email"]').val();
     if(email== ''){
     var data1 = "This is a required field.";                                
     $("<div class='msgg' style='color: #e02b27;'>"+data1+"</div>").insertAfter("form#myform");
      setTimeout(function () {
      $('.msgg').hide();
      }, 5000);
        }
      else{
      $('#myform')[0].reset();
      var data = "You have been registered to your to our newsletter!";                                
      $("<div class='msg'>"+data+"</div>").insertAfter("form#myform");
      setTimeout(function () {
      $('.msg').hide();
      }, 5000);
      }
      });
    });
</script>

How to show an error or success message after clicking on the button by Jqueryexpoundsofttechsolution