firstChild property

Gets a reference to the first child in the childNodes collection of the object.

Syntax

JavaScript

p = object.firstChild

Property values

Type: Object

The first child object.

Standards information

Examples

The following code example implements the firstChild attribute to get the first child element of an object.


<!DOCTYPE html>

<html>
<head>
  <title>firstChild</title>
</head>
<body>
  <ul id="oList">
    <li>List Item 1</li>
    <li>List Item 2</li>
    <li>List Item 3</li>
    <li>List Item 4</li>
  </ul>
  <script>
    var oFirstChild = document.getElementById('oList').firstChild;

    console.log("The first UL child is actually a text node: " + oFirstChild);
  </script>
</body>
</html>

See also

a
abbr
address
area
attribute
b
base
bdo
blockQuote
body
button
caption
cite
code
col
colGroup
comment
dd
del
dfn
div
dl
documentType
dt
em
embed
fieldSet
form
frame
head
hn
hr
html
i
iframe
img
input type=button
input type=checkbox
input type=email
input type=file
input type=image
input type=number
input type=password
input type=radio
input type=range
input type=reset
input type=search
input type=submit
input type=tel
input type=text
input type=url
ins
kbd
label
legend
li
link
map
menu
ol
option
p
pre
ProcessingInstruction
q
s
samp
script
select
small
span
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
title
tr
u
ul
var
Reference
lastChild
Conceptual
About the W3C Document Object Model

 

 

Show:
© 2014 Microsoft