title: Element involuntarily toggles upon keyboard typing
body: <p>I'm in the midst of creating my first 'real' website and try to add some responsiveness to my layout and navigation: <a href="http://www.dknytkom.dk/forside/" rel="nofollow">www.dknytkom.dk/forside/</a></p>
  
  <p>I use alot of addClass and removeClass to menu items as well as toggling corresponding to the width of the browser window. So far so good.</p>
  
  <p>Problem is that my search field disappears upon focus when view on my iPhone. I have a vague suspicion it is to do when my jquery commands that make it go away when the document width is changed. But really I'm at a loss.</p>
  
  <p>Also the toggling of the menu items tends to go awire when clicking on the menu elements even though I conditioned them to wait for the document to load. Any suggestions?</p>
  
  <p><a href="http://jsfiddle.net/KbMnV/" rel="nofollow">I've tried to create a jsfiddle from where the full code can be inspected:</a> </p>
  
  <pre><code>$(document).ready(function() {
  
          var $introbrowserwidth= $(window).width();
  
          $soeg = $('a.soege-knap');
          $mobnav = $('a.mob-nav');
          $soegelist = $('div#search-table') ;
          $searchtable = $('#search-table') ;
          $soegefelt = $('ul.menu-item-holder &gt; #searchfield');
          $menuknap = $('li a.menu-knap');
          $menu = $('div.menu')
          $menulist = $('.menu li')
          $emneoversigt = $('#emneoversigt')
          $emneoversigtlistitem = $('#emneoversigt li')
          $('.mob-nav').css('cursor','pointer');
          $temamenu = $('#tema-menu');
  
  
          if ($introbrowserwidth &lt;=480) {
          $soegelist.addClass('displaynone');
          $soegefelt.addClass('displaynone');
          $('#menudiv').removeClass('displayblock').addClass('displaynone');
          $('#menudiv &gt; ul').addClass('background-colour7 zebra');
          $('#menudiv a').addClass('displayblock');
  
          }       
          else{
                  $menulist.removeClass('listitem').addClass('inlineblock');
                  $menu.removeClass('displaynone').addClass('displayblock');
                  $soegefelt.removeClass('displaynone').addClass('inlineblock');
  
              };
  
                  $soeg.on("click",function(e) { 
  
                                              e.preventDefault();
  
                                              $soegelist.toggleClass('displayblock');
                                              $soegefelt.toggleClass('displayblock');
                                              $emneoversigt.removeClass().addClass('displaynone');
                                              $soeg.toggleClass('soege-knap-aktiv');
                                              $('#menudiv').removeClass('displayblock').addClass('displaynone');
                                              $('#menudiv &gt; ul').removeClass('background-colour7 zebra');
  
                                              $menuknap.removeClass('menu-knap-aktiv');
  
                                              $('ul.menu-item-holder').toggleClass('expandheight');
  
                                              });
  
  
                      $menuknap.on("click",function(e) { 
  
                                              e.preventDefault();
  
                                              var $menutilstand =  $(window).width();
  
                                              $menulist.addClass('padding5');
                                              $menuknap.toggleClass('menu-knap-aktiv');
                                              $soeg.removeClass('soege-knap-aktiv');
                                              $soegelist.removeClass().addClass('displaynone');
                                              $('ul.menu-item-holder').removeClass('height expandheight')
                                              $('#menudiv &gt; ul').addClass('background-colour7 zebra');
  
  
                                              if($soeg.hasClass('soege-knap-aktiv')) { 
                                              $soeg.removeClass('soege-knap-aktiv');
                                                  $('ul.menu-item-holder').removeClass('height expandheight');
  
                                                  };
  
                                                  if ( ($menutilstand &lt;=480) &amp;&amp; ($('#menudiv').hasClass('displaynone')) ) {
                                                  $('#menudiv').removeClass('displaynone').addClass('displayblock');
                                                  $($menulist).removeClass('displayblock').addClass('padding5 listitem');
                                                  $soegefelt.removeClass('displayblock');
  
  
                                                  } else {    $('#menudiv').removeClass('displayblock').addClass('displaynone');}
  
                                              if ($('ul#menu-item-holder').hasClass('expandheight')){
                                                      $('ul#menu-item-holder').removeClass('expandheight').addClass('height')
                                                          }
  
  
                                              });
  
  
  
                                  $('#indexbtn').on("click",function(e) { 
                                  $('#emneoversigt').toggleClass('displayblock');
                              e.preventDefault(); })
  
  
  
  
  $( window ).resize(function()
                                              {
  
                                      var browserwidth= $(window).width();
  
                                      $emneoversigt.removeClass('listitem').addClass('displaynone');
                                      $('.menu').removeClass('padding5');
                                      $emneoversigt.removeClass('displayblock').addClass('displaynone');
                                      $menuknap.removeClass('menu-knap-aktiv');
                                      $('*').removeClass('height expandheight')
                                      $('#menudiv &gt; ul').removeClass('background-colour7 zebra');
                                      $soeg.removeClass('soege-knap-aktiv');
  
  
                                              if(browserwidth &lt;= 480 ) {
  
                                                                  $soegefelt.addClass('displaynone');
  $temamenu.addClass('displaynone');
  $soegelist.removeClass('inlineblock displayblock').addClass('displaynone');
                                                                  $menu.addClass('displaynone');
                                                                  $menulist.removeClass('inlineblock').addClass('listitem');
                                                                  $('ul.menu-item-holder').removeClass('height');
                                                                      $menulist.removeClass('listitem displayblock').addClass('displaynone');
                                                                  $('#menudiv').removeClass('displayblock');
  
                                              $('ul#menu-item-holder').addClass('height');
  
  
                                               }
                                              else {      $('li#searchfield').removeClass().addClass('inlineblock');
                                                                  $soegelist.removeClass('displaynone').addClass('inlineblock');
                                                                  $menu.addClass('displayblock');                                             $temamenu.removeClass('displaynone');                                                           $menulist.removeClass('listitem stroke displayblock ').addClass('padding5 inlineblock');
  $('ul.menu-item-holder').addClass('height');
                                                          }
                                          })
  
   });
  </code></pre>