Results 1 to 3 of 3

Thread: [RESOLVED] dom question

  1. #1
    Join Date
    Mar 2012

    resolved [RESOLVED] dom question

    hi all!!! I have a question relative to DOM in this code:

    <script type="text/javascript">
    function myFunction()
        alert("Length of the list="+document.getElementById("users_list").childNodes.length);
        <dl id="users_list">
            <dt onclick="myFunction()">
                This is the first Item
    The output of this code yields “Length of the list=3”, that is, the number of children of the element dl is three but he number of items in the list is only one!! Why??

    Thank you very much!!

  2. #2
    Join Date
    Feb 2006
    there are 2 textnodes and one dt node, which contains one text node.

    try it like this:
        <dl id="users_list"><dt onclick="myFunction()">
                This is the first Item
    The new lines between the tags in your code are childnodes, just as they would be if you had any character text there.

  3. #3
    Join Date
    Mar 2012
    Thank you very much mrhoo!!! now it works!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles