SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I want to show three elements of the list however it only shows the first

    Good night!
    I am studying the book Only JS Javascript (sitepoint).
    In Chapter 3, I'm working with DOM's.

    Code JavaScript:
    window.onload = function ()
    {
        var listItems = document.getElementsByTagName("li");
     
        for (var i = 0; i < listItems.length; i++)
        {
            //alert(listItems[i].nodeValue);
            alert(listItems[i].childNodes[i].nodeValue);
        }
    }

    It only takes the first element of the list in case Paragraph.

    Because the loop is not being done? I want the alert to show me also the other two, unordered list, and list items.
    HTML Code:
    <body>
        <p>
            Há três tipos de elementos neste corpo:
        </p>
    
        <ul>
            <li>parágrafo</li>
            <li>lista não ordenada</li>
            <li>item de lista</li>
        </ul>
    </body>
    Thanks a lot
    Last edited by Mittineague; Sep 17, 2013 at 18:17. Reason: reformatting bbcode tags


Bookmarks

Posting Permissions

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