Gets a value indicating whether the object can contain child objects.
Syntax
| JavaScript | |
|---|
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.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/canHaveChildren.htm
<!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
- acronym
- address
- applet
- area
- article
- aside
- b
- base
- baseFont
- bgSound
- big
- blockQuote
- body
- br
- button
- caption
- center
- cite
- code
- col
- colGroup
- comment
- custom
- dd
- del
- dfn
- dir
- div
- dl
- dt
- em
- embed
- fieldSet
- figcaption
- figure
- font
- footer
- form
- frame
- frameSet
- head
- header
- hgroup
- hn
- hr
- html
- i
- iframe
- img
- input type=button
- input type=checkbox
- input type=file
- input type=hidden
- input type=image
- input type=password
- input type=radio
- input type=reset
- input type=submit
- input type=text
- input type=url
- input type=number
- input type=email
- input type=range
- input type=tel
- ins
- isIndex
- kbd
- label
- legend
- li
- link
- listing
- map
- mark
- marquee
- menu
- nav
- nextID
- noBR
- noFrames
- noScript
- object
- ol
- option
- p
- plainText
- pre
- q
- rt
- ruby
- s
- samp
- script
- section
- select
- small
- span
- strike
- strong
- style
- sub
- sup
- table
- tBody
- td
- textArea
- tFoot
- th
- tHead
- title
- tr
- tt
- u
- ul
- var
- wbr
- xml
- xmp
- Reference
- appendChild
- createElement
- createTextNode
Send comments about this topic to Microsoft
Build date: 11/28/2012