title: jQuery: How to check if an element exceeds the browser window's size, and how to reposition it
body: <p>I have this code:</p>
  
  <pre><code>var pos = $(this).offset();
  var width = $(this).width();
  
  userPreviewCon.css({
       left: (pos.left + 30) + 'px',
       top: (pos.top + 15) + 'px'
  }).fadeIn();
  </code></pre>
  
  <p>...which is for positioning a popup window relative to the element that the mouse is pointing.
  <br /><br />
  But when an element is close to the window's border, some of the tooltip is not visible because part of it exceeds the window size. The question is: &nbsp;how can I reposition the tooltip to no longer exceed the window's border?</p>