Skip to content

Commit

Permalink
2023/07/07 時点の英語版に基づき更新
Browse files Browse the repository at this point in the history
  • Loading branch information
mfuji09 committed Jun 20, 2024
1 parent 37769b1 commit ad9397b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
23 changes: 15 additions & 8 deletions files/ja/web/api/document/createcomment/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: Document.createComment()
title: "Document: createComment() メソッド"
short-title: createComment()
slug: Web/API/Document/createComment
l10n:
sourceCommit: acfe8c9f1f4145f77653a2bc64a9744b001358dc
---

{{APIRef("DOM")}}
Expand All @@ -9,26 +12,30 @@ slug: Web/API/Document/createComment

## 構文

```
CommentNode = document.createComment(data);
```js-nolint
createComment(data)
```

### 引数

- _data_
- `data`
- : 文字列で、コメントに追加されるデータを含みます。

### 返値

新しい {{domxref("Comment")}} オブジェクトです。

##

```js
var docu = new DOMParser().parseFromString("<xml></xml>", "application/xml");
var comment = docu.createComment(
const docu = new DOMParser().parseFromString("<xml></xml>", "application/xml");
const comment = docu.createComment(
"This is a not-so-secret comment in your document",
);

docu.getElementsByTagName("xml")[0].appendChild(comment);
docu.querySelector("xml").appendChild(comment);

alert(new XMLSerializer().serializeToString(docu));
console.log(new XMLSerializer().serializeToString(docu));
// 表示結果: <xml><!--This is a not-so-secret comment in your document--></xml>
```

Expand Down
34 changes: 21 additions & 13 deletions files/ja/web/api/document/createelement/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: Document.createElement()
title: "Document: createElement() メソッド"
short-title: createElement()
slug: Web/API/Document/createElement
l10n:
sourceCommit: acfe8c9f1f4145f77653a2bc64a9744b001358dc
---

{{APIRef("DOM")}}
Expand All @@ -9,16 +12,20 @@ slug: Web/API/Document/createElement

## 構文

```js
let element = document.createElement(tagName[, options]);
```js-nolint
createElement(tagName)
createElement(tagName, options)
```

### 引数

- _tagName_
- `tagName`
- : 生成される要素の型を特定する文字列です。生成される要素の {{domxref("Node.nodeName", "nodeName")}} は _tagName_ の値で初期化されます。このメソッドで修飾名 ("html:a" など) を使用しないでください。 HTML 文書で呼び出すと、 `createElement()` は要素を生成する前に _tagName_ を小文字に変換します。 Firefox, Opera, Chrome では、 `createElement(null)``createElement("null")` のように動作します。
- _options_{{optional_inline}}
- : 省略可能な `ElementCreationOptions` オブジェクトで、 `is` という名前のプロパティをひとつ持ち、その値は前に `customElements.define()` を使用して定義したカスタム要素の名前です。詳しくは[ウェブコンポーネントの例](#ウェブコンポーネントの例)を参照してください。
- `options` {{optional_inline}}
- : 以下のプロパティを持つオブジェクトです。
- `is`
- : 事前に `customElements.define()` で定義したカスタム要素のタグ名です。
詳しくは[ウェブコンポーネントの例](#ウェブコンポーネントの例)を参照してください。

### 返値

Expand All @@ -36,12 +43,13 @@ let element = document.createElement(tagName[, options]);

```html
<!doctype html>
<html>
<html lang="ja">
<head>
<title>||Working with elements||</title>
<meta charset="UTF-8" />
<title>要素のの操作</title>
</head>
<body>
<div id="div1">The text above has been created dynamically.</div>
<div id="div1">上記のテキストは動的に生成されました。</div>
</body>
</html>
```
Expand All @@ -56,7 +64,7 @@ function addElement() {
const newDiv = document.createElement("div");

// いくつかの内容を与えます
const newContent = document.createTextNode("Hi there and greetings!");
const newContent = document.createTextNode("みなさん、こんにちは!");

// テキストノードを新規作成した div に追加します
newDiv.appendChild(newContent);
Expand All @@ -74,7 +82,7 @@ function addElement() {
### ウェブコンポーネントの例

以下の例の断片は [expanding-list-web-component](https://github.com/mdn/web-components-examples/tree/master/expanding-list-web-component)
の例から取ったものです ([ライブでもご覧ください](https://mdn.github.io/web-components-examples/expanding-list-web-component/))。この場合、カスタム要素は {{domxref("HTMLUListElement")}} を拡張し、 {{htmlelement("ul")}} 要素を表します。
の例から取ったものです[ライブでもご覧ください](https://mdn.github.io/web-components-examples/expanding-list-web-component/)。この場合、カスタム要素は {{domxref("HTMLUListElement")}} を拡張し、 {{htmlelement("ul")}} 要素を表します。

```js
// 要素のためのクラスを作成
Expand All @@ -84,12 +92,12 @@ class ExpandingList extends HTMLUListElement {
super();

// コンストラクターの定義は簡略化のため省略します。
...
//
}
}

// 新しい要素を定義
customElements.define('expanding-list', ExpandingList, { extends: "ul" });
customElements.define("expanding-list", ExpandingList, { extends: "ul" });
```

この要素のインスタンスをプログラムで生成したければ、次の行のような呼び出しを使用します。
Expand Down

0 comments on commit ad9397b

Please sign in to comment.