<p>Is there a function like <code>document.getElementById("FirstDiv").clear()</code>?</p>

[{'answer_id': 13766, 'author': 'EBGreen', 'author_id': 1358, 'author_profile': 'https://Stackoverflow.com/users/1358', 'pm_score': 0, 'selected': False, 'text': '<p>You should be able to use the .RemoveNode method of the node or the .RemoveChild method of the parent node.</p>\n'}, {'answer_id': 13769, 'author': 'eplawless', 'author_id': 1370, 'author_profile': 'https://Stackoverflow.com/users/1370', 'pm_score': 6, 'selected': False, 'text': "<p>If you want to clear the div and remove all child nodes, you could put:</p>\n\n<pre><code>var mydiv = document.getElementById('FirstDiv');\nwhile(mydiv.firstChild) {\n  mydiv.removeChild(mydiv.firstChild);\n}\n</code></pre>\n"}, {'answer_id': 13773, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 0, 'selected': False, 'text': '<p>You should probably use a JavaScript library to do things like this.</p>\n\n<p>For example, MochiKit has a function <a href="http://mochikit.com/doc/html/MochiKit/DOM.html#fn-removeelement" rel="nofollow noreferrer">removeElement</a>, and jQuery has <a href="http://docs.jquery.com/Manipulation/remove#expr" rel="nofollow noreferrer">remove</a>.</p>\n'}, {'answer_id': 13779, 'author': 'Polsonby', 'author_id': 137, 'author_profile': 'https://Stackoverflow.com/users/137', 'pm_score': 2, 'selected': False, 'text': "<p>You have to remove any event handlers you've set on the node before you remove it, to avoid memory leaks in IE</p>\n"}, {'answer_id': 14782, 'author': 'Jason Bunting', 'author_id': 1790, 'author_profile': 'https://Stackoverflow.com/users/1790', 'pm_score': 8, 'selected': True, 'text': '<p>To answer the original question - there are various ways to do this, but the following would be the simplest.</p>\n\n<p>If you already have a handle to the child node that you want to remove, i.e. you have a JavaScript variable that holds a reference to it:</p>\n\n<pre><code>myChildNode.parentNode.removeChild(myChildNode);\n</code></pre>\n\n<p>Obviously, if you are not using one of the numerous libraries that already do this, you would want to create a function to abstract this out:</p>\n\n<pre><code>function removeElement(node) {\n    node.parentNode.removeChild(node);\n}\n</code></pre>\n\n<hr>\n\n<p>EDIT: As has been mentioned by others: if you have any event handlers wired up to the node you are removing, you will want to make sure you disconnect those before the last reference to the node being removed goes out of scope, lest poor implementations of the JavaScript interpreter leak memory.</p>\n'}, {'answer_id': 3388480, 'author': 'Chris Jacob', 'author_id': 114140, 'author_profile': 'https://Stackoverflow.com/users/114140', 'pm_score': 2, 'selected': False, 'text': '<p>A jQuery solution</p>\n\n<p><strong>HTML</strong></p>\n\n<pre><code>&lt;select id="foo"&gt;\n  &lt;option value="1"&gt;1&lt;/option&gt;\n  &lt;option value="2"&gt;2&lt;/option&gt;\n  &lt;option value="3"&gt;3&lt;/option&gt;\n&lt;/select&gt;\n</code></pre>\n\n<p><strong>Javascript</strong></p>\n\n<pre><code>// remove child "option" element with a "value" attribute equal to "2"\n$("#foo &gt; option[value=\'2\']").remove();\n\n// remove all child "option" elements\n$("#foo &gt; option").remove();\n</code></pre>\n\n<p>References:</p>\n\n<p><a href="http://api.jquery.com/attribute-equals-selector/" rel="nofollow noreferrer" title="Attribute Equals Selector [name=value]">Attribute Equals Selector [name=value]</a></p>\n\n<blockquote>\n  <p>Selects elements that have the\n  specified attribute with a value\n  exactly equal to a certain value.</p>\n</blockquote>\n\n<p><a href="http://api.jquery.com/child-selector/" rel="nofollow noreferrer">Child Selector (“parent > child”)</a></p>\n\n<blockquote>\n  <p>Selects all direct child elements\n  specified by "child" of elements\n  specified by "parent"</p>\n</blockquote>\n\n<p><a href="http://api.jquery.com/remove/" rel="nofollow noreferrer">.remove()</a></p>\n\n<blockquote>\n  <p>Similar to .empty(), the .remove()\n  method takes elements out of the DOM.\n  We use .remove() when we want to\n  remove the element itself, as well as\n  everything inside it. In addition to\n  the elements themselves, all bound\n  events and jQuery data associated with\n  the elements are removed.</p>\n</blockquote>\n'}, {'answer_id': 7750327, 'author': 'eagle', 'author_id': 961780, 'author_profile': 'https://Stackoverflow.com/users/961780', 'pm_score': 2, 'selected': False, 'text': '<p>Use the following code:</p>\n\n<pre><code>//for Internet Explorer\ndocument.getElementById("FirstDiv").removeNode(true);\n\n//for other browsers\nvar fDiv = document.getElementById("FirstDiv");\nfDiv.removeChild(fDiv.childNodes[0]); //first check on which node your required node exists, if it is on [0] use this, otherwise use where it exists.\n</code></pre>\n'}, {'answer_id': 40543830, 'author': 'Gibolt', 'author_id': 974045, 'author_profile': 'https://Stackoverflow.com/users/974045', 'pm_score': 4, 'selected': False, 'text': '<h1>Modern Solution - <code>child.remove()</code></h1>\n<p>For your use case:</p>\n<pre><code>document.getElementById(&quot;FirstDiv&quot;).remove()\n</code></pre>\n<p>This is recommended by W3C since late 2015, and is <strong>vanilla JS</strong>. All major browsers support it.</p>\n<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove" rel="noreferrer">Mozilla Docs</a></p>\n<p><a href="https://caniuse.com/#feat=childnode-remove" rel="noreferrer">Supported Browsers</a> - 96% May 2020</p>\n'}, {'answer_id': 44698638, 'author': 'Vivek Tiwari', 'author_id': 7921020, 'author_profile': 'https://Stackoverflow.com/users/7921020', 'pm_score': 1, 'selected': False, 'text': "<pre><code>    var p=document.getElementById('childId').parentNode;\n    var c=document.getElementById('childId');\n    p.removeChild(c);\n    alert('Deleted');\n</code></pre>\n\n<p>p is parent node and c is child node<br>\nparentNode is a JavaScript variable which contains parent reference<br>\n<br>\nEasy to understand</p>\n"}]
['https://Stackoverflow.com/questions/13763', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/184/']