innerHTML Property
Sets or retrieves the HTML between the start and end tags of the object.
Syntax
HTML N/A Scripting object.innerHTML [ = sHTML ]
Possible Values
sHTML String that specifies the content between the start and end tags. The property is read/write with no default value (see Remarks).
Remarks
The innerHTML property is read-only on the FRAMESET, HTML, HEAD, TABLE, TBODY, TFOOT, THEAD, TITLE, and TR objects.
The innerHTML property takes a string that specifies a valid combination of text and elements.
When the innerHTML property is set, 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.
This property is accessible at run time as of Microsoft® Internet Explorer 5. Removing elements at run time, before the closing tag has been parsed, could prevent other areas of the document from rendering.
When using innerHTML to insert script, you must include the DEFER attribute in the SCRIPT element.
You can change the value of the TITLE element using the document.title property.
To change the contents of the TABLE, TFOOT, THEAD, and TR elements, use the table object model. For example, use the rowIndex property or the rows collection to retrieve a reference to a specific table row. You can add or delete rows using the insertRow and deleteRow methods. To retrieve a reference to a specific cell, use the cellIndex property or the cells collection. You can add or delete rows using the insertCell and deleteCell methods. To change the content of a particular cell, use the innerHTML property.
Example
This example uses the innerHTML property to change the text of a paragraph when an onmouseover event occurs. The affected text and any tags within it are changed by the onmouseover and onmouseout 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>This example uses 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
[ Object Name ] Platform Version Win16: Win32: Mac: Unix: WinCE: Version data is listed when the mouse hovers over a link, or the link has focus. A, ACRONYM, ADDRESS, B, BDO, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, custom, DD, DEL, DFN, DIR, DIV, DL, DT, EM, FIELDSET, FONT, FORM, FRAMESET, HEAD, Hn, HTML, I, IFRAME, INS, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, NEXTID, NOBR, OL, OPTION, P, PRE, Q, RT, RUBY, S, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, STRONG, STYLE, SUB, SUP, TABLE, TBODY, TD, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP
See Also
Did you find this topic useful? Suggestions for other topics? write us!
© 1999 microsoft corporation. all rights reserved. terms of use.