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

Workshop  |  DHTML, HTML & CSS

insertAdjacentHTML Method


Inserts the given HTML text into the element at the location. If the text contains HTML tags, the method parses and formats the text as it is inserted.

Syntax

object.insertAdjacentHTML(sWhere, sText)

Parameters

sWhereRequired. Specifies the position where insert the HTML text is to be inserted. This position can be one of the following:
beforeBeginInserts the text immediately before the element.
afterBeginInserts the text after the start of the element but before all other content in the element.
beforeEndInserts the text immediately before the end of the element but after all other content in the element.
afterEndInserts the text immediately after the end of the element.
sTextRequired. HTML text to insert. The string can be a combination of text and HTML tags. This must be well-formed, valid HTML or this method will fail.

Return Value

No return value.

Remarks

You cannot insert text while the document is loading. Wait for the onload event before attempting to call this method.

When inserting script using the insertAdjacentHTML method you must include the DEFER attribute in the SCRIPT tag.

Example

The following example shows use of the insertAdjacentHTML method 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.insertAdjacentHTML("afterBegin",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

innerHTML, insertAdjacentText, outerHTML


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