title: jQuery UI - prevent resizing of dialog outside the parent div
body: <p><strong>PROBLEM:</strong>
  When doing resize on dialog, I want to prevent it from going outside parent div <code>dialog-container</code>. For some reason <code>containment</code> is not working as I expected. What else can I try?</p>
  
  <p><a href="https://i.stack.imgur.com/9wMjo.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9wMjo.gif" alt="enter image description here"></a></p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;div id="top"&gt;&lt;/div&gt;
  &lt;div id="dialog-container"&gt;
    &lt;div id="dialog"&gt;My dialog&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>JS:</strong></p>
  
  <pre><code>$(document).ready(function() {
      jQuery("#dialog").dialog({
                              autoOpen:true,
                              modal: false,
                              resizable: true,
                              draggable: true,
                              closeOnEscape: true,
                              title: "Title",
          open: function(){
              jQuery('.ui-widget-overlay').bind('click',function(){
                  jQuery('#dialog').dialog('close');
              })
          }
      }).parent().draggable({
          containment: '#dialog-container'
      }).resizable({
          containment: '#dialog-container'
      });
  });
  </code></pre>
  
  <p><strong>JSFIDDLE:</strong> <a href="https://jsfiddle.net/4zfmbktr/" rel="nofollow noreferrer">https://jsfiddle.net/4zfmbktr/</a></p>