title: JQuery Validating image with size < 2mb
body: <p>I want to validate my input upload image with only allow image with size less than 2mb with jQuery. I find around but mostly guides are about validating dimension (width and height of image) Here's my code:</p>
  
  <p>html:</p>
  
  <pre><code>&lt;input type="file" name="logo" id="logo" accept="image/*"&gt;
  &lt;p class="error_line" style="display: none"&gt;Image Only&lt;/p&gt;
  
  &lt;input class="btn btn-primary submit-btn" style="margin:10px 0; width: auto" type="submit" value="Create"&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>$(document).ready(function () {
      var _URL = window.URL || window.webkitURL;
      $("#logo").change(function(e) {
          var file, img;
          if ((file = this.files[0])) {
              img = new Image();
              img.onload = function() {
                  $('.submit-btn').prop('disabled', false);
                  $(".error_line").fadeOut();
              };
              img.onerror = function() {
                  $('.submit-btn').prop('disabled', true);
                  $(".error_line").fadeIn();
              };
              img.src = _URL.createObjectURL(file);
          }
      });
  });
  </code></pre>