EN
이 콘텐츠는 한국어로 제공되지 않아 영어 버전으로 표시됩니다.

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.

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=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
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

 

 

표시:
© 2014 Microsoft