innerHTML Property

DHTML, HTML, & CSS

 
Click to return to the DHTML, HTML & CSS home page    
index Property     innerText Property     DHTML Properties    

innerHTML Property


Sets or retrieves the HTML between the start and end tags of the object.

Syntax

HTMLN/A
Scriptingobject.innerHTML [ = sHTML ]

Possible Values

sHTMLString 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 feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

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;

This feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
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

insertAdjacentHTML


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.