aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/document/createelementns/index.html
blob: c1bf1fade61c1e4025357d18d307d7195028d96c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
title: Document.createElementNS()
slug: Web/API/Document/createElementNS
translation_of: Web/API/Document/createElementNS
---
<div>{{ApiRef("DOM")}}</div>

<p>지정된 네임스페이스 URI와 적합한 이름으로 엘리먼트를 만든다.</p>

<p>네임스페이스 URI를 지정하지 않고 엘리먼트를 만들려면 <a href="createElement" title="createElement">createElement</a>메소드를 사용하라.</p>

<h2 id="Syntax" name="Syntax">Syntax</h2>

<pre class="brush: js"><var>var element</var> = <var>document</var>.createElementNS(<var>namespaceURI</var>, <var>qualifiedName</var>[, options]);
</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt><code>namespaceURI</code></dt>
 <dd>A string that specifies the <a class="external" href="http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/glossary.html#dt-namespaceURI">namespace URI</a> to associate with the element. The <a href="/en-US/docs/DOM/element.namespaceURI">namespaceURI</a> property of the created element is initialized with the value of <code>namespaceURI</code>. See <a href="#Valid Namespace URIs">Valid Namespace URIs</a>.</dd>
 <dt><code>qualifiedName</code></dt>
 <dd>A string that specifies the type of element to be created. The <a href="/en-US/docs/DOM/element.nodeName">nodeName</a> property of the created element is initialized with the value of <code>qualifiedName</code>.</dd>
 <dt><code>options</code><span class="inlineIndicator optional optionalInline">Optional</span></dt>
 <dd>An optional <code>ElementCreationOptions</code> object containing a single property named <code>is</code>, whose value is the tag name for a custom element previously defined using <code>customElements.define()</code>. For backwards compatibility with previous versions of the <a class="external external-icon" href="https://www.w3.org/TR/custom-elements/">Custom Elements specification</a>, some browsers will allow you to pass a string here instead of an object, where the string's value is the custom element's tag name. See <a class="external external-icon" href="https://developers.google.com/web/fundamentals/primers/customelements/#extendhtml">Extending native HTML elements</a> for more information on how to use this parameter.</dd>
 <dd>The new element will be given an <code>is</code> attribute whose value is the custom element's tag name. Custom elements are an experimental feature only available in some browsers.</dd>
</dl>

<h3 id="Return_value">Return value</h3>

<p>The new <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element" title="The Element interface represents an object of a Document. This interface describes methods and properties common to all kinds of elements. Specific behaviors are described in interfaces which inherit from Element but add additional functionality."><code>Element</code></a>.</p>

<h2 id="Example" name="Example"><a id="Valid Namespace URIs" name="Valid Namespace URIs">Valid Namespace URIs</a></h2>

<ul>
 <li>HTML - Use <code>http://www.w3.org/1999/xhtml</code></li>
 <li>SVG - Use <code>http://www.w3.org/2000/svg</code></li>
 <li>XBL - Use <code>http://www.mozilla.org/xbl</code></li>
 <li>XUL - Use <code>http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul</code></li>
</ul>

<h2 id="Example" name="Example">Example</h2>

<p>This creates a new &lt;div&gt; element in the <a href="/en-US/docs/XHTML" title="XHTML">XHTML</a> namespace and appends it to the vbox element. Although this is not an extremely useful <a href="/en-US/docs/XUL" title="XUL">XUL</a> document, it does demonstrate the use of elements from two different namespaces within a single document:</p>

<pre class="brush:xml">&lt;?xml version="1.0"?&gt;
&lt;page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      xmlns:html="http://www.w3.org/1999/xhtml"
      title="||Working with elements||"
      onload="init()"&gt;

&lt;script type="text/javascript"&gt;&lt;![CDATA[
 var container;
 var newdiv;
 var txtnode;

 function init(){
   container = document.getElementById("ContainerBox");
   newdiv = document.createElementNS("http://www.w3.org/1999/xhtml","div");
   txtnode = document.createTextNode("This is text that was constructed dynamically with createElementNS and createTextNode then inserted into the document using appendChild.");
   newdiv.appendChild(txtnode);
   container.appendChild(newdiv);
 }

]]&gt;&lt;/script&gt;

 &lt;vbox id='ContainerBox' flex='1'&gt;
  &lt;html:div&gt;
   The script on this page will add dynamic content below:
  &lt;/html:div&gt;
 &lt;/vbox&gt;

&lt;/page&gt;
</pre>

<div class="note">
<p>The example given above uses inline script which is not recommended in XHTML documents. This particular example is actually an XUL document with embedded XHTML, however, the recommendation still applies.</p>
</div>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM WHATWG', "#dom-document-createelementns", "Document.createElement")}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{Compat("api.Document.createElementNS")}}</p>

<h2 id="See_also" name="See_also">See also</h2>

<ul>
 <li><a href="createElement">document.createElement</a></li>
 <li><a href="createTextNode">document.createTextNode</a></li>
 <li><a href="../Node/namespaceURI">Node.namespaceURI</a></li>
 <li><a class="external" href="http://www.w3.org/TR/1999/REC-xml-names-19990114">Namespaces in XML</a></li>
</ul>