JavaScript Reference/Javascript Methods/removeChild

Материал из Web эксперт
Перейти к: навигация, поиск

"removeChild()" Example

    
<html>
<body>
<script language="JavaScript">
function function2() {
    var m = "New Element";
    var n = document.createElement("li");
    n.appendChild(document.createTextNode(m));
    document.getElementById("myList").appendChild(n); 
} 
function function2() {
    myList.removeChild(myList.lastChild);
}
</script>
<ul id="myList">
   <li>First list element</li>
   <li>Second list element</li>
</ul>
<input type="button" value="Add list item" onClick="function2();">
<input type="button" value="Remove added items" onClick="function2();">
</body>
</html>



"removeChild()" is applied to

+----------------+--------------------------------------------------------------+
| Applied_To     |<a>                             <acronym>                     |
|                |<address>                       <applet>                      |
|                |<area>                          attribute                     |
|                |<b>                             <base>                        |
|                |<basefont>                      <bdo>                         |
|                |<big>                           <blockquote>                  |
|                |<body>                          <br>                          |
|                |<button>                        <caption>                     |
|                |<center>                        <cite>                        |
|                |<code>                          <col>                         |
|                |<colgroup>                      <comment>                     |
|                |<dd>                            <del>                         |
|                |<dfn>                           <dir>                         |
|                |<div>                           <dl>                          |
|                |<dt>                            <em>                          |
|                |<fieldset>                      <font>                        |
|                |<form>                          <frame>                       |
|                |<frameset>                      <head>                        |
|                |<hn>                            <hr>                          |
|                |<html>                          <i>                           |
|                |<iframe>                        <img>                         |
|                |<input>                         <input type="button">         |
|                |<input type="checkbox">         <input type="file">           |
|                |<input type="hidden">           <input type="image">          |
|                |<input type="password">         <input type="radio">          |
|                |<input type="reset">            <input type="submit">         |
|                |<input type="text">             <ins>                         |
|                |<isindex>                       <kbd>                         |
|                |<label>                         <legend>                      |
|                |<li>                            <link>                        |
|                |<listing>                       <map>                         |
|                |<marquee>                       <menu>                        |
|                |<meta>                          <noframes>                    |
|                |<noscript>                      <object>                      |
|                |<ol>                            <optgroup>                    |
|                |<option>                        <p>                           |
|                |<param>                         <plaintext>                   |
|                |<pre>                           <q>                           |
|                |<s>                             <samp>                        |
|                |<script>                        <select>                      |
|                |<small>                         <span>                        |
|                |<strike>                        <strong>                      |
|                |<style>                         <sub>                         |
|                |<sup>                           <table>                       |
|                |<tbody>                         <td>                          |
|                |<textarea>                      <tfoot>                       |
|                |<th>                            <thead>                       |
|                |<title>                         <tr>                          |
|                |<tt>                            <u>                           |
|                |<ul>                            <var>                         |
|                |<xmp>                                                         |
+----------------+--------------------------------------------------------------+



"removeChild()" Syntax, Parameters and Note

Note:
Removes a child node created by the createTextNode() method.
    
Syntax:
    
document.getElementById("elementID").removeChild(param1)
document.all.elementID.removeChild(param1) // IE only
Parameters:
    param1   Required; the name of the element to be removed.