--- id: bad87fee1348bd9aed908826 title: 使用 jQuery 更改元素的 CSS challengeType: 6 forumTopicId: 16776 required: - link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css' dashedName: change-the-css-of-an-element-using-jquery --- # --description-- 也能用 jQuery 直接改變 HTML 標籤的 CSS。 jQuery 有一個 `.css()` 方法,能改變標籤的 CSS。 下面的代碼效果是把顏色變藍: ```js $("#target1").css("color", "blue"); ``` 這與通常的 CSS 聲明略有不同,因爲這個 CSS 屬性和它的值在英文引號裏,並且它們用逗號而不是冒號間隔開。 刪除 jQuery 選擇器,留下一個空的 `document ready function` 。 選擇 `target1`,並將其顏色更改爲紅色。 # --hints-- `target1` 元素應該有紅色文本。 ```js assert($('#target1').css('color') === 'rgb(255, 0, 0)'); ``` 應該僅用 jQuery 給元素添加這些 class。 ```js assert(!code.match(/class.*animated/g)); ``` # --seed-- ## --seed-contents-- ```html