Magazine |
| | Community |
| | Workshop |
| | Tools & Samples |
| | Training |
| | Site Info |
|
|
||||||||
|
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
sWhere Required. Specifies the position where insert the HTML text is to be inserted. This position can be one of the following:
beforeBegin Inserts the text immediately before the element. afterBegin Inserts the text after the start of the element but before all other content in the element. beforeEnd Inserts the text immediately before the end of the element but after all other content in the element. afterEnd Inserts the text immediately after the end of the element. sText Required. 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);
Applies To
A, ADDRESS, AREA, B, BASEFONT, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COMMENT, DD, DFN, DIR, DIV, DL, DT, EM, FIELDSET, FONT, FORM, FRAMESET, Hn, HR, HTMLAREA, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, NOBR, OL, OPTION, P, PLAINTEXT, PRE, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TD, TEXTAREA, TH, 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.