I have this code :
$(document).ready(function() {
  $('#search').keyup(function() {
    var search = $('#search').val();
    console.log(search);
    if (search.length !== 0 || search !== "") {
      $('.wrapper').css({
        "background-color": "#000",
        "opacity": 0.8
      });
      $('.post').remove();
    } else {
      location.reload(false);
    };
  });
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="#">
  <button type="submit">Search</button>
  <input type="text" name="search" id="search" />
</form>but the problem is that whatever  put space at the beginning in the input element, the function is not working (it goes on to run $('.wrapper').css({"background-color":"#000","opacity":0.8}); and $('.post').remove(); ).
 
     
     
     
     
     
    