--- id: bad87eee1348bd9aede07836 title: 要素の id を設定する challengeType: 0 videoUrl: 'https://scrimba.com/c/cN6MEc2' forumTopicId: 18279 dashedName: set-the-id-of-an-element --- # --description-- クラスに加えて、各 HTML 要素は `id` 属性を持つこともできます。 `id` 属性を使用するいくつかの利点があります: 単一の要素のスタイルを指定するために `id` を使用することができます。また、JavaScript で特定の要素を選択して変更できることも後ほど学習します。 `id` 属性は一意でなければなりません。 ブラウザはこの制限を強制しませんが、ベストプラクティスとして広く受け入れられています。 したがって、複数の要素に同じ `id` 属性を与えないようにしてください。 `h2` 要素に `cat-photo-app` という id を与える例を以下に示します: ```html

``` # --instructions-- `form` 要素に `cat-photo-form` という id を設定してください。 # --hints-- `form` 要素は、`cat-photo-form` という id を持つ必要があります。 ```js assert($('form').attr('id') === 'cat-photo-form'); ``` # --seed-- ## --seed-contents-- ```html

CatPhotoApp

Click here to view more cat photos.

A cute orange cat lying on its back.

Things cats love:

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats


``` # --solutions-- ```html

CatPhotoApp

Click here to view more cat photos.

A cute orange cat lying on its back.

Things cats love:

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats


```