title: How to select elements within a variable using jQuery?
body: <p>I'm trying to make a simple image browser for TinyMCE which I am using in my CMS. As part of this I need to detect whether the user has selected an existing image, so I can display the "edit" form instead of the "choose an image form".</p>
  
  <pre><code>var selected_html = ed.selection.getContent();
  var $elem = $(selected_html);
  console.log($elem);
  </code></pre>
  
  <p>The first function returns the user selected text from the editor window as a string of HTML. I then would like to use jQuery (although plain javascript is just ok too) to check if this string contains an img tag before subsequently grabbing the src and title attributes for editing.</p>
  
  <p>Now I've got as far as getting the html to turn into an object. But after this I can't manage to search it for the img element. After reading this (<a href="https://stackoverflow.com/questions/2352072/how-to-manipulate-html-within-a-jquery-variable">How to manipulate HTML within a jQuery variable?</a>) I tried:</p>
  
  <pre><code>$elem.find('img');
  </code></pre>
  
  <p>But it just comes out as an "undefined" object...</p>
  
  <p>I think I'm missing something fairly obvious here (it is getting late), but after an hour I still can't figure out how to grab the img tag from the selection. :(</p>
  
  <p>Many thanks in advance.</p>