[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/API/Element/outerHTML [Back]  [Original]

Element.outerHTML - Web API | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Element.outerHTML

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

outerHTML (element) HTML . .

HTML innerHTML .

In this article

js
var content = element.outerHTML;

element.outerHTML = htmlString;

outerHTML HTML DOMString . outerHTML htmlString DOM .

SyntaxError

HTML outerHTML SyntaxError .

NoModificationAllowedError

Document.documentElement Document outerHTML NoModificationAllowedError .

outerHTML .

js
// HTML:
// <div id="d"><p>Content</p><p>Further Elaborated</p></div>

d = document.getElementById("d");
console.log(d.outerHTML);

// '<div id="d"><p>Content</p><p>Further Elaborated</p></div>'
//    .

outerHTML .

js
// HTML:
// <div id="container"><div id="d">This is a div.</div></div>

container = document.getElementById("container");
d = document.getElementById("d");
console.log(container.firstChild.nodeName); // "DIV" .

d.outerHTML = "<p>This paragraph replaced the original div.</p>";
console.log(container.firstChild.nodeName); // "P" .

// #d div    ,
//  p  .

outerHTML . . .

js
var div = document.createElement("div");
div.outerHTML = '<div class="test">test</div>';
//   DOMException  .
console.log(div.outerHTML); // : "<div></div>"

, outerHTML .

js
var p = document.getElementsByTagName("p")[0];
console.log(p.nodeName); // "P" .
p.outerHTML = "<div>This div replaced a paragraph.</div>";
console.log(p.nodeName); //  "P" .

Specification
HTML
# dom-element-outerhtml


Web Proxy Viewer  |  New URL  |  Original Page