not selector is getting ignored

not selector is getting ignored

Hi,

I want to hide my search field when the user clicks ANYWHERE but not on the search field itself and the icon which activates the search field.

I tried it like this:

  1. $(function() {
  2. $('.top-searchField').hide();
  3. $('.icon-close-searchField').hide();
  4. });

  5. $(document).ready(function() {
  6. $('#search-icon').click(function() {
  7. $('.top-searchField').show('slow');
  8. $('.icon-top-searchField').hide('slow');
  9. $('.icon-close-searchField').show('slow');
  10. });

  11. $('div').not('.top-searchField, #search-icon').click(function() {
  12. $('.icon-top-searchField').hide('slow');
  13. $('.top-searchField').hide('slow');
  14. });
  15. });

My icon and my search field look like this:

  1. <input placeholder="Type something..." class="top-searchField" type="text" />
  2. <span id="search-icon" class="icon-search icon-white icon-top-searchField"></span>

Every time I click on the icon it shows me the search field but then it's getting hidden again. It is just totally ignoring my not selector!

How do I fix this?