1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

[object HTMLLIElement]

Discussion in 'JavaScript' started by papa_face, Sep 6, 2007.

  1. #1
    Hello,
    Can someone tell me why I keep getting:
    [object HTMLLIElement][object HTMLLIElement][object HTMLLIElement]
    Code (markup):
    Outputted in Firefox and [object] in IE for this code please?

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
    <head>
    <title>Tag Name Locator</title>
    <meta http-equiv="Content-Type"
    content="text/html; charset=utf-8" />
    </head>
    <body>
    <p>
    There are 3 different types of element in this body:
    </p>
    <ul>
    	<li>
    	paragraph
    	</li>
    		<li>
    	unordered list
    		</li>
    			<li>
    			list item
    			</li>
    </ul>
    </body>
    <script type="text/javascript">
    var listItems = document.getElementsByTagName("li");
    for (var i = 0; i < listItems.length; i++)
    {
    document.write(listItems[i]);
    }
    </script>
    </html>
    Code (markup):
    The output is:
    There are 3 different types of element in this body:
    
        * paragraph
        * unordered list
        * list item
    
    [object HTMLLIElement][object HTMLLIElement][object HTMLLIElement]
    Code (markup):
    Shouldn't it be showing me the content of the li tag?
     
    papa_face, Sep 6, 2007 IP
  2. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #2
    Doesn't matter solved. Should be document.write(listItems.innerHTML);
     
    papa_face, Sep 6, 2007 IP