/    Sign up×
Community /Pin to ProfileBookmark

[object HTMLLIElement]

Hello,
Can someone tell me why I keep getting:

[CODE][object HTMLLIElement][object HTMLLIElement][object HTMLLIElement][/CODE]

Outputted in Firefox and [object] in IE for this code please?

[CODE]<!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]

The output is:

[CODE]There are 3 different types of element in this body:

* paragraph
* unordered list
* list item

[object HTMLLIElement][object HTMLLIElement][object HTMLLIElement][/CODE]

Shouldn’t it be showing me the content of the li tag?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 06.2007 — [B]listItems[i][/B] is a reference (the object) to a list item.

The contents would be [B]listItems[i].firstChild.data[/B] or [B]listItems[i].innerHTML[/B]
Copy linkTweet thisAlerts:
@papa_faceauthorSep 06.2007 — Thanks ?
×

Success!

Help @papa_face spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...