JavaScript Reference/Javascript Collections/childNodes

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

"childNodes" Example

    
<html>
<head>
<script language="JavaScript">
function function1() {
    var m = document.all.myBody.childNodes;
    alert(m.length) 
}
</script>
</head>
<body id="myBody">
<input id=myB 
       type="button" 
       value="How many child nodes have this body element?" 
       onclick="function1()">
</body>
</html>



"childNodes" is applied to

+----------------+--------------------------------------------------------------+
| Applied_To     |<a>                             attribute                     |
|                |<acronym>                       <address>                     |
|                |<applet>                        <area>                        |
|                |<b>                             <base>                        |
|                |<basefont>                      <bdo>                         |
|                |<big>                           <blockquote>                  |
|                |<body>                          <br>                          |
|                |<button>                        <caption>                     |
|                |<center>                        <cite>                        |
|                |<code>                          <col>                         |
|                |<colgroup>                      <comment>                     |
|                |<dd>                            <del>                         |
|                |<dfn>                           <dir>                         |
|                |<div>                           <dl>                          |
|                |document                        <dt>                          |
|                |<em>                            <embed>                       |
|                |<fieldset>                      <font>                        |
|                |<form>                          <frame>                       |
|                |<frameset>                      <head>                        |
|                |<hn>                            <hr>                          |
|                |<html>                          <i>                           |
|                |<iframe>                        <img>                         |
|                |<ins>                           <isindex>                     |
|                |<kbd>                           <label>                       |
|                |<legend>                        <li>                          |
|                |<link>                          <listing>                     |
|                |<map>                           <marquee>                     |
|                |<menu>                          <meta>                        |
|                |<noframes>                      <noscript>                    |
|                |<object>                        <ol>                          |
|                |<optgroup>                      <option>                      |
|                |<p>                             <param>                       |
|                |<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>                                                         |
+----------------+--------------------------------------------------------------+



"childNodes" JavaScript properties and JavaScript methods

JavaScript properties and JavaScript methods
 
item(), length, urns()



"childNodes" Syntax Parameters and Note

Note:
Returns an array of all first-generation nodes, including text nodes, of the object.
    
Syntax:
    
document.getElementById("elementID").childNodes // returns all child nodes
document.getElementById("elementID").childNodes(param1) // returns an individual 
child node
document.all.elementID.childNodes // IE only 
document.all.elementID.childNodes(param1) // IE only

    param1   Required; zero-based index