| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/API/Element/innerHTML | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.
* Some parts of this feature may have varying levels of support.
Element (property) innerHTML (element) HTML XML .
:
<div>, <span>, <noembed> (&), (<), (>) , innerHTML "&", "<" ,">" . Node.textContent .
(element) HTML (document) , insertAdjacentHTML() .
const content = element.innerHTML;
element.innerHTML = htmlString;
(element) HTML DOMString . Setting the value of innerHTML () , htmlString HTML , .
SyntaxErrorHTML , innerHTML .
NoModificationAllowedError Document HTML .
innerHTML (property) , HTML .
innerHTML (user agent) HTML XML . .
let contents = myElement.innerHTML;
HTML .
: HTML, XML . .
innerHTML (content) .
, (document) body (attribute) , .
document.body.innerHTML = "";
HTML , "<" HTML "<" . HTML (raw text - ) . <pre> . innerHTML . , .
document.documentElement.innerHTML =
"<pre>" + document.documentElement.innerHTML.replace(/</g, "<") + "</pre>";
innerHTML , ? , .
DocumentFragment DOM .<template> , <template> content (attribute) 1 DocumentFragment .DocumentFragment .innerHTML . .
const name = "John";
// assuming 'el' is an HTML DOM element
el.innerHTML = name; // harmless in this case
// ...
name = "<script>alert('I am John in an annoying alert!')</script>";
el.innerHTML = name; // harmless in this case
cross-site scripting , . HTML5 innerHTML <script> .
<script> , JavaScript , innerHTML . :
const name = "<img src='x' >";
el.innerHTML = name; // shows the alert
innerHTML . Node.textContent . HTML (raw text) .
:
, innerHTML . , innerHTML addons.mozilla.org .
innerHTML .
function log(msg) {
var logElem = document.querySelector(".log");
var time = new Date();
var timeStr = time.toLocaleTimeString();
logElem.innerHTML += timeStr + ": " + msg + "<br/>";
}
log("Logging mouse events inside this container...");
log() toLocaleTimeString() Date , . "log" .
MouseEvent (mousedown, click, mouseenter ) :
function logEvent(event) {
var msg =
"Event <strong>" +
event.type +
"</strong> at <em>" +
event.clientX +
", " +
event.clientY +
"</em>";
log(msg);
}
, .
var boxElem = document.querySelector(".box");
boxElem.addEventListener("mousedown", logEvent);
boxElem.addEventListener("mouseup", logEvent);
boxElem.addEventListener("click", logEvent);
boxElem.addEventListener("mouseenter", logEvent);
boxElem.addEventListener("mouseleave", logEvent);
HTML .
<div class="box">
<div><strong>Log:</strong></div>
<div class="log"></div>
</div>
"box" <div> . class "log" <div> .
CSS .
.box {
width: 600px;
height: 300px;
border: 1px solid black;
padding: 2px 4px;
overflow-y: scroll;
overflow-x: auto;
}
.log {
margin-top: 8px;
font-family: monospace;
}
. .
| Specification |
|---|
| HTML # dom-element-innerhtml |
Node.textContent Node.innerTextElement.insertAdjacentHTML()DOMParserXMLSerializerThis page was last modified on 2025 10 10 by MDN contributors.
ElementactiveViewTransitionariaActiveDescendantElementariaAtomicariaAutoCompleteariaBrailleLabelariaBrailleRoleDescriptionariaBusyariaCheckedariaColCountariaColIndexariaColIndexTextariaColSpanariaControlsElementsariaCurrentariaDescribedByElementsariaDescriptionariaDetailsElementsariaDisabledariaErrorMessageElementsariaExpandedariaFlowToElementsariaHasPopupariaHiddenariaInvalidariaKeyShortcutsariaLabelariaLabelledByElementsariaLevelariaLiveariaModalariaMultiLineariaMultiSelectableariaOrientationariaOwnsElementsariaPlaceholderariaPosInSetariaPressedariaReadOnlyariaRelevantariaRequiredariaRoleDescriptionariaRowCountariaRowIndexariaRowIndexTextariaRowSpanariaSelectedariaSetSizeariaSortariaValueMaxariaValueMinariaValueNowariaValueTextassignedSlotattributeschildElementCountchildrenclassListclassNameclientHeightclientLeftclientTopclientWidthcurrentCSSZoomcustomElementRegistryelementTimingfirstElementChildidinnerHTMLlastElementChildlocalNamenamespaceURInextElementSiblingouterHTMLpartprefixpreviousElementSiblingrolescrollHeightscrollLeftscrollLeftMaxscrollTopscrollTopMaxscrollWidthshadowRootslottagNameafter()animate()append()ariaNotify()attachShadow()before()checkVisibility()closest()computedStyleMap()getAnimations()getAttribute()getAttributeNames()getAttributeNode()getAttributeNodeNS()getAttributeNS()getBoundingClientRect()getClientRects()getElementsByClassName()getElementsByTagName()getElementsByTagNameNS()getHTML()hasAttribute()hasAttributeNS()hasAttributes()hasPointerCapture()insertAdjacentElement()insertAdjacentHTML()insertAdjacentText()matches()moveBefore()prepend()pseudo()querySelector()querySelectorAll()releasePointerCapture()remove()removeAttribute()removeAttributeNode()removeAttributeNS()replaceChildren()replaceWith()requestFullscreen()requestPointerLock()scroll()scrollBy()scrollIntoView()scrollIntoViewIfNeeded()scrollTo()setAttribute()setAttributeNode()setAttributeNodeNS()setAttributeNS()setCapture()setHTML()setHTMLUnsafe()setPointerCapture()startViewTransition()toggleAttribute()afterscriptexecuteanimationcancelanimationendanimationiterationanimationstartauxclickbeforeinputbeforematchbeforescriptexecutebeforexrselectblurclickcompositionendcompositionstartcompositionupdatecontentvisibilityautostatechangecontextmenucopycutdblclickDOMActivateDOMMouseScrollfocusfocusinfocusoutfullscreenchangefullscreenerrorgesturechangegestureendgesturestartgotpointercaptureinputkeydownkeypresskeyuplostpointercapturemousedownmouseentermouseleavemousemovemouseoutmouseovermouseupmousewheelMozMousePixelScrollpastepointercancelpointerdownpointerenterpointerleavepointermovepointeroutpointeroverpointerrawupdatepointerupscrollscrollendscrollsnapchangescrollsnapchangingsecuritypolicyviolationtouchcanceltouchendtouchmovetouchstarttransitioncanceltransitionendtransitionruntransitionstartwebkitmouseforcechangedwebkitmouseforcedownwebkitmouseforceupwebkitmouseforcewillbeginwheelAbortControllerAbortSignalAbstractRangeAttrCDATASectionCharacterDataCommentCustomEventDOMErrorDOMExceptionDOMImplementationDOMParserDOMTokenListDocumentDocumentFragmentDocumentTypeEventEventTargetHTMLCollectionMutationObserverMutationRecordNamedNodeMapNodeNodeIteratorNodeListProcessingInstructionQuotaExceededErrorRangeShadowRootStaticRangeTextTreeWalkerXMLDocumentXPathEvaluatorXPathExpressionXPathResultXSLTProcessorYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |