JavaScript Reference/Javascript Properties/lastChild

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

"lastChild" Example

   <source lang="javascript">
   

<html> <body> <script language="JavaScript"> function newElem(myT) {

   var newI = document.createElement("LI")
   newI.innerHTML = myT
   return newI

} function function1(form) {

   var newI = newElem(form.enter.value);
   var fLi = document.getElementById("myL").firstChild;
   document.getElementById("myL").replaceChild(newI, fLi);

} function function2(form) {

   var newI = newElem(form.enter.value);
   var fLi = document.getElementById("myL").lastChild;
   document.getElementById("myL").replaceChild(newI, fLi);

} </script> <form> <input type="text" name="enter" size="50"> <button onClick="function1(this.form);"> Replace first item</button> <button onClick="function2(this.form);"> Replace last item</button>

  • First List Item
  • Second List Item

</form> </body> </html>


     </source>
   
  


"lastChild" is applied to

   <source lang="javascript">

+----------------+--------------------------------------------------------------+ | Applied_To |<a> <acronym> | | |<address> <applet> | | |<area> attribute | | | <base> | | |<basefont> |

| |
|

| |<body>
| | |<button> |

| |
|

| | <col> | | |<colgroup> <comment> | | |

| | | <dir> |

| |
|

| |

| | |<embed> <fieldset> | | | <form> | | |<frame> <frameset> | | |<head> <hn> |

| |
<html> |

| | <iframe> | | |<img> <input type="button"> | | |<input type="checkbox"> <input type="file"> | | |<input type="image"> <input type="password"> | | |<input type="radio"> <input type="reset"> | | |<input type="submit"> <input type="text"> | | | <isindex> | | | <label> |

| |<legend>
  • | | |<link> <listing> | | |<map> <marquee> | | |<menu> <meta> | | |<noframes> <noscript> | | |<object>
      | | |<optgroup> <option> | | |

      <param> | | |<plaintext>

                               |
      |                |                                                        |
      |                |                          <script>                      |
      |                |<select>                                               |
      |                |                                                |
      |                |                        <style>                       |
      |                |                                                    |
      |                |                         <tbody>                       |
      |                |                          |
      |                |                             
        | | | <xmp> | +----------------+--------------------------------------------------------------+ </source>

        "lastChild" Syntax and Note

        <source lang="javascript"> Note: Read-only property. Returns the last child in the childNodes.

        Syntax:

        document.getElementById("elementID").lastChild document.all.elementID.lastChild // IE only


        </source>

      <textarea> | | |<tfoot> |

      | |<thead> <title> |

      | |