title: Change position of tooltip on window resize
body: <p>I'm using jQuery UI to create a tooltip for a search input field. I then want to position the tooltip according to the size of the browser window (top if less than 768px, left if more).</p>
  
  <p>I initialise the tooltip with:</p>
  
  <pre><code>$('#search').tooltip({'placement':'top'});
  </code></pre>
  
  <p>Then I have this function to change the placement depending on the window size:</p>
  
  <pre><code>$(window).on('resize', function() {
      if ($(window).width &lt; 768) {
          $("#damSearch").tooltip({'placement':'top'});
      } else {
          $("#damSearch").tooltip({'placement':'left'});
      }
  }).trigger('resize');
  </code></pre>
  
  <p>For some reason it's not working. The tooltip initialises fine but when I resize the browser above 768px it still appears positioned to the top.</p>
  
  <p><strong>[EDIT]</strong></p>
  
  <p>I've been away for a few days and have just come back to try and resolve this problem.
  I've installed Modernizr because I intend using it elsewhere on the site and so I thought I'd use Modernizr.mq to detect the window resizing. I also read elsewhere that the code to reposition the tooltip should be in its own self contained function, so this is the function:</p>
  
  <pre><code>function positionTooltip() {
      if (Modernizr.mq('(min-width: 768px)')) {
          $("#damSearch").tooltip({'placement':'left'});
      } else {
          $("#damSearch").tooltip({'placement':'bottom'});
      }
  }
  </code></pre>
  
  <p>This is then followed in my Javascript file with:</p>
  
  <pre><code>$(document).ready(function() {
  
      positionTooltip();
      // Fire the function on page load
  
      $(window).resize(positionTooltip);
      // Fire function on window resize event
  </code></pre>
  
  <p>Unfortunately it's still not working correctly.
  The tooltip appears correctly positioned when the page is first loaded, but if I then resize the browser the position is not updated. If I reload the page however the tooltip's position is changed accordingly.</p>
  
  <p>It's as if the resize event is not triggering the function.</p>
  
  <p><strong>[/EDIT]</strong></p>
  
  <p>As ever all help and advice is greatly appreciated.
  Tony.</p>