all
alt
ch
dir
id
min
rel
top
url
URL
urn
Expand Minimize

canHaveChildren property

Gets a value indicating whether the object can contain child objects.

Syntax

JavaScript

p = object.canHaveChildren

Property values

Type: Boolean

Indicates whether the object can contain child objects.

false (false)

The object cannot be a parent to child objects.

true (true)

The object can be a parent to child objects.

Remarks

Objects do not have to contain children for the canHaveChildren property to return true. This property is useful in determining whether objects can be appended as children.

Examples

This example uses the canHaveChildren property to add a new object to the first element in a document that can contain children.


<!DOCTYPE html>
<html >
<head>
        <title></title>
</head>
<body>
 <script type="text/javascript">   
   function fnAddChild() {
     var oNewObject = document.createElement("span");
     var oNewText = document.createTextNode("Test");
     oNewObject.appendChild(oNewText);
     for (var i = 0; i < document.all.length; i++) {
       if (document.all[i].canHaveChildren == true) {
         document.all[i].appendChild(oNewObject);
         break;
       }
     }
   }
</script>
<input type=button value="Add Child" onclick="fnAddChild()">
<div id=oGrandParent style="background-color: #CFCFCF;">
<span>Some text here</span>
</div>

</body>
</html>

See also

a
abbr
address
area
article
aside
b
base
bgSound
blockQuote
body
br
button
caption
cite
code
col
colGroup
comment
custom
dd
del
dfn
div
dl
dt
em
embed
fieldSet
figcaption
figure
footer
form
frame
head
header
hgroup
hn
hr
html
i
iframe
img
input type=button
input type=checkbox
input type=email
input type=file
input type=hidden
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
mark
menu
nav
object
ol
option
p
pre
q
rt
ruby
s
samp
script
section
select
small
span
strong
style
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
title
tr
u
ul
var
Reference
appendChild
createElement
createTextNode

 

 

Show:
© 2014 Microsoft