title: jQuery: Trigger keydown only in specific div
body: <p>I have a page with couple of DIV elements. When user presses the CTRL+ENTER button combo, I need to display (via alert()) the text, that user previously selected. I found the <a href="http://www.gmarwaha.com/blog/2009/06/16/ctrl-key-combination-simple-jquery-plugin/" rel="nofollow">solution</a> and it works like a charm, but there is still one thing left. </p>
  
  <p>I need to make event trigger, only when selected text is inside a DIV with class "main_content". I've tried to assign <code>keyup</code> to $('DIV.main_content'), but it does not work.</p>
  
  <p>Is there a way to make event trigger only if text inside $('DIV.main_content') selected?</p>
  
  <p>Here is a working code that triggers on the whole document:</p>
  
  <pre><code>// Get user selection text on page
  function getSelectedText() {
      if (window.getSelection) {
          return window.getSelection();
      }
      else if (document.selection) {
          return document.selection.createRange().text;
      }
          return '';
  }
  
  $(document).ready(function(){
      $(document).keydown(function(e) {
          if(e.which == 13 &amp;&amp; e.ctrlKey) {
          alert(getSelectedText());
          return false;
          }
      });
  });
  </code></pre>
  
  <p><a href="http://jsfiddle.net/NCgYZ/1/" rel="nofollow">See the code with markup in jsFiddle</a></p>