Magazine |
| | Community |
| | Workshop |
| | Tools & Samples |
| | Training |
| | Site Info |
|
|
||||||||
|
Sets or retrieves the HTML between the start and end tags of the current object.
Syntax
HTML N/A Scripting object.innerHTML [ = sHTML ]
Possible Values
sHTML String containing the contents between the start and end tags. The property is read/write with no default value.
Remarks
The property takes a string containing a valid combination of text and tags, except for HTML, HEAD, and TITLE tags.
When setting the property, the given string completely replaces the existing content of the object. If the string contains HTML tags, the string is parsed and formatted as it is placed into the document.
The property cannot be set while the document is loading. Wait for the onload event before attempting to set it. If a tag is dynamically created using TextRange, innerHTML, or outerHTML, use JScript™ (compatible with ECMA 262 language specification) to create new events to handle the newly formed tags (VBScript is not supported).
When inserting script using innerHTML you must include the DEFER attribute in the SCRIPT tag.
InnerHTML is read-only on the following objects: HTML, TABLE, TBODY, TFOOT, THEAD, TR.
Example
The following example shows use of the innerHTML property. The affected text, and any tags within it, are changed by the events.
Sample Code
<P onmouseover="this.innerHTML='<B>Mouse out to change back.</B>'" onmouseout="this.innerHTML='<I>Mouse over again to change.</I>'"> <I>Mouse over this text to change it.</I></P>The following example shows use of the innerHTML property to insert script into the page.
Sample Code
var sHTML="<input type=button onclick=" + "go2()" + " value='Click Me'><BR>" var sScript='<SCRIPT DEFER>' sScript = sScript + 'function go2(){ alert("Hello from inserted script.") }' sScript = sScript + '</script' + '>'; ScriptDiv.innerHTML=sHTML + sScript;
Applies To
A, ACRONYM, ADDRESS, B, BDO, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, DD, DEL, DFN, DIR, DIV, DL, DT, EM, FIELDSET, FONT, FORM, HEAD, Hn, HTML, HTMLAREA, I, IFRAME, INS, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, NEXTID, NOBR, OL, OPTION, P, PRE, Q, RB, RT, RUBY, S, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, STRONG, STYLE, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP
See Also
Does this content meet your programming needs? Write us!
© 1998 Microsoft Corporation. All rights reserved. Terms of use.