blob: dab03631d17fc13f4aa546a59ad7fd947b7bafd6 (
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
|
<header><h1>is</h1></header><div class="section-content">
<p>The <code>is</code> <a href="../global_attributes">global attribute</a> allows you to specify that a standard HTML element should behave like a defined custom built-in element (see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements">Using custom elements</a> for more details).</p> <p>This attribute can only be used if the specified custom element name has been successfully <a href="https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define">defined</a> in the current document, and extends the element type it is being applied to.</p>
</div>
<h2 id="examples">Examples</h2>
<div class="section-content">
<p>The following code is taken from our <a href="https://github.com/mdn/web-components-examples/tree/main/word-count-web-component" target="_blank">word-count-web-component</a> example (<a href="https://mdn.github.io/web-components-examples/word-count-web-component/" target="_blank">see it live also</a>).</p> <div class="code-example">
<p class="example-header"><span class="language-name">js</span></p>
<pre data-signature="jVc95/umnT02cy/WQ+QXP/GX79Q/NzKV4VzHQjCaIMo=" data-language="js"><span class="token comment">// Create a class for the element</span>
<span class="token keyword">class</span> <span class="token class-name">WordCount</span> <span class="token keyword">extends</span> <span class="token class-name">HTMLParagraphElement</span> <span class="token punctuation">{</span>
<span class="token function">constructor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token comment">// Always call super first in constructor</span>
<span class="token keyword">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// Constructor contents omitted for brevity</span>
<span class="token comment">// …</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token comment">// Define the new element</span>
customElements<span class="token punctuation">.</span><span class="token function">define</span><span class="token punctuation">(</span><span class="token string">"word-count"</span><span class="token punctuation">,</span> WordCount<span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token keyword">extends</span><span class="token operator">:</span> <span class="token string">"p"</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</pre>
</div> <div class="code-example">
<p class="example-header"><span class="language-name">html</span></p>
<pre data-signature="2HWc9XXr7N6633Peud0V5KO5Agg7fFBZQXZH96uYCqM=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>p</span> <span class="token attr-name">is</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>word-count<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>p</span><span class="token punctuation">></span></span>
</pre>
</div>
</div>
<h2 id="specifications">Specifications</h2>
<div class="_table"><table class="standard-table">
<thead><tr><th scope="col">Specification</th></tr></thead>
<tbody><tr><td><a href="https://html.spec.whatwg.org/multipage/custom-elements.html#attr-is">HTML Standard <br><small># attr-is</small></a></td></tr></tbody>
</table></div>
<h2 id="browser_compatibility">Browser compatibility</h2>
<div class="_table"><table>
<thead>
<tr id="bct-browser-type">
<th></th>
<th colspan="6">Desktop</th>
<th colspan="6">Mobile</th>
</tr>
<tr id="bct-browsers">
<th></th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
<th>WebView Android</th>
<th>Chrome Android</th>
<th>Firefox for Android</th>
<th>Opera Android</th>
<th>Safari on IOS</th>
<th>Samsung Internet</th>
</tr>
</thead>
<tbody><tr>
<th><code>is</code></th>
<td class="bc-supports-yes">67</td>
<td class="bc-supports-yes">79</td>
<td class="bc-supports-yes">63</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-yes">54</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-yes">67</td>
<td class="bc-supports-yes">67</td>
<td class="bc-supports-yes">63</td>
<td class="bc-supports-yes">48</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-yes">9.0</td>
</tr></tbody>
</table></div>
<h2 id="see_also">See also</h2>
<div class="section-content"><ul> <li>All <a href="../global_attributes">global attributes</a>.</li> </ul></div><div class="_attribution">
<p class="_attribution-p">
© 2005–2023 MDN contributors.<br>Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.<br>
<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/is" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/is</a>
</p>
</div>
|