JavaScript Reference/Javascript Properties/firstChild — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:21, 26 мая 2010
"firstChild" 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>
"firstChild" 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> | | |
<textarea> | | |<tfoot> | | |<thead> <title> |
| || | | | | | <xmp> | +----------------+--------------------------------------------------------------+ </source>
"firstChild" Syntax and Note
<source lang="javascript"> Note: Read-only property. Returns the first child.
Syntax:
document.getElementById("elementID").firstChild document.all.elementID.firstChild // IE only
</source>