canHaveHTML property
Retrieves a Boolean value that indicates whether the element can contain HTML formatted text.
If the canHaveHTML property returns false, then do not write the innerHTML property.
The canHaveHTML property is similar to the canHaveChildren property.
When the canHaveChildren property returns false, then the canHaveHTML property also returns false, although some elements can have children, but cannot contain HTML formatted text.
See the example below.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read-only.
Possible values:
Boolean, one of the following values:
Element cannot contain HTML formatted text. | |||||||
Element can contain HTML formatted text. |
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the canHaveHTML property:
|
||||
<head> <script type="text/javascript"> function Init () { var message = ""; var content = document.getElementById ("content"); if (('canHaveChildren' in content) && ('canHaveHTML' in content)) { var child = content.firstChild; while (child) { if (child.tagName) { if (child.canHaveChildren) { message += child.tagName + " elements can have children.<br />"; } else { message += child.tagName + " elements cannot have children.<br />"; } if (child.canHaveHTML) { message += child.tagName + " elements can have HTML content.<br />"; } else { message += child.tagName + " elements cannot have HTML content.<br />"; } } child = child.nextSibling; } } else { message = "Your browser does not support this example!"; } var info = document.getElementById ("info"); info.innerHTML = message; } </script> </head> <body onload="Init ()"> canHaveChildren and canHaveHTML property test for different elements: <div id="content"> <div id="info" style="background-color:#e0a0a0; width:300px"></div> <select> <option>first option</option> <option>second option</option> </select> <br /> <button>Test button</button> </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CommentNode
HTML elements:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:reset, input:submit, input:text, ins, isindex, kbd, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
External links:
User Contributed Comments