Q:

Extract HTML content from string in JQuery

I have a textarea, inside this textarea, dynamic HTML content are bind like
<div id="HDWebAllTemplateHTMLListMessage">
    <div id="header">This is a header</div>
    <div class="main">
      <div id="content">This is my main content.</div>
      <div id="sidebar">This is a sidebar</div>
    </div>
    <div id="footer">This is my footer</div>
</div>

Somehow i want html content inside .main class.  I tried but not able to get html content.
var textAreaContent=$($('#HDWebAllTemplateHTMLListMessage').text());
var divContent=textAreaContent.find('.main');
console.log(divContent.innerHTML);

A:

Do you really need to use textarea? 
You can try like below. But if you don't need it. The azizsagi example is working fine.
JAVASCRIPT
var newdiv1 = $("<div class='dummy'></div>");
$("textarea").after(newdiv1); /* create dummy div */
var tgt = newdiv1;
var main = tgt.html($("textarea").text()).find(".main").text();
tgt.text(main);
/* newdiv1.remove(); */ // If you want to remove the element after you get what you need

JSFiddle : https://jsfiddle.net/synz/amgtLwex/

