 <p>You can do something like this,</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function() { function removeNode(str, nodeName) { var pattern = '&lt;'+nodeName+'&gt;[\\s\\w]+&lt;\/'+nodeName+'&gt;'; var regex = new RegExp(pattern, 'gi'); return str.replace(regex, '').replace(/^\s*[\r\n]/gm, ''); } $("#myBtn").on('click', function () { var txt = $("#txtArea").text(); var newText = removeNode(txt, 'PublisherImprintName'); $('#txtArea').text(newText); }); });</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; &lt;textarea id="txtArea" rows="10" cols="50"&gt; &lt;PublisherInfo&gt; &lt;PublisherName&gt;Ask question&lt;/PublisherName&gt; &lt;PublisherLocation&gt;ph&lt;/PublisherLocation&gt; &lt;PublisherImprintName&gt;ask stackoverflow&lt;/PublisherImprintName&gt; &lt;PublisherURL&gt;stackoverflow.com&lt;/PublisherURL&gt; &lt;/PublisherInfo&gt; &lt;/textarea&gt; &lt;button id="myBtn"&gt;Button&lt;/button&gt;</code></pre> </div> </div> </p> <p><strong>Edit:</strong></p> <p>For your another question, you can do this..</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function() { function removeNodeButRetain(str, nodeName) { var pattern = '&lt;\/?'+nodeName+'&gt;'; var regex = new RegExp(pattern, 'gi'); return str.replace(regex, '').replace(/^\s*[\r\n]/gm, ''); } $("#myBtn").on('click', function() { var txt = $("#txtArea").text(); var newText = removeNodeButRetain(txt, 'PublisherInfo'); $('#txtArea').text(newText); }); });</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; &lt;textarea id="txtArea" rows="10" cols="50"&gt; &lt;PublisherInfo&gt; &lt;PublisherName&gt;Ask question&lt;/PublisherName&gt; &lt;PublisherLocation&gt;ph&lt;/PublisherLocation&gt; &lt;PublisherImprintName&gt;ask stackoverflow&lt;/PublisherImprintName&gt; &lt;PublisherURL&gt;stackoverflow.com&lt;/PublisherURL&gt; &lt;/PublisherInfo&gt; &lt;/textarea&gt; &lt;button id="myBtn"&gt;Button&lt;/button&gt;</code></pre> </div> </div> </p>