Microsoft HomeproductssearchsupportshopWrite Us   Microsoft Home
Magazine
 |  Community
 |  Workshop
 |  Tools & Samples
 |  Training
 |  Site Info

Workshop  |  DHTML, HTML & CSS

innerHTML Property


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

Syntax

HTMLN/A
Scriptingobject.innerHTML [ = sHTML ]

Possible Values

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

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

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;

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

See Also

insertAdjacentHTML


Does this content meet your programming needs? Write us!

Back to topBack to top

© 1998 Microsoft Corporation. All rights reserved. Terms of use.

 

Magazine Home
Ask Jane
DHTML Dude
Extreme XML
For Starters
More or Hess
Servin' It Up
Site Lights
Web Men Talking
Member Community Home
Benefits: Freebies & Discounts
Benefits: Promote Your Site
Benefits: Connect with Your Peers
Benefits at a Glance
Online Special-Interest Groups
Your Membership
SBN Stores
Join Now
Workshop Home
Essentials
Content & Component Delivery
Component Development
Data Access & Databases
Design
DHTML, HTML & CSS
Extensible Markup Language (XML)
Languages & Development Tools
Messaging & Collaboration
Networking, Protocols & Data Formats
Reusing Browser Technology
Security & Cryptography
Server Technologies
Streaming & Interactive Media
Web Content Management
Workshop Index
Tools & Samples Home
Tools
Samples, Headers, Libs
Images
Sounds
Style Sheets
Web Fonts
Training Home
SBN Live Seminars
SBN Live Chats
Courses
Peer Support
CD-ROM Training
Books & Training Kits
Certification
SBN Home
New to SBN?
What's New on SBN
Site Map
Site Search
Glossary
Write Us
About This Site