I've tried all the ways from the answers here, but have not worked. So far I have done:
jQuery(function($) {
  $(document).ready(function(){
      $("#sb-search").click(function(){
          $(".sb-search").addClass("sb-search-open");
          $("body").click(function(){
              $(".sb-search").hasClass("sb-search-open");
              $(this).removeClass("sb-search-open");
          });
      });
  });
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div id="sb-search" class="sb-search">
    <form autocomplete="off" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
        <input class="sb-search-input" type="search" value="" name="s" id="s">
        <input class="sb-search-submit" type="submit" value="">
        <span class="sb-icon-search"></span>
    </form>
</div>
</body>I want to remove the .sb-search-open class after clicked outside the div
 
     
    