feat: add 'back/front end' in curriculum (#42596)

* chore: rename APIs and Microservices to include "Backend" (#42515)

* fix typo

* fix typo

* undo change

* Corrected grammar mistake

Corrected a grammar mistake by removing a comma.

* change APIs and Microservices cert title

* update title

* Change APIs and Microservices certi title

* Update translations.json

* update title

* feat(curriculum): rename apis and microservices cert

* rename folder structure

* rename certificate

* rename learn Markdown

* apis-and-microservices -> back-end-development-and-apis

* update backend meta

* update i18n langs and cypress test

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* fix: add development to front-end libraries (#42512)

* fix: added-the-word-Development-to-front-end-libraries

* fix/added-the-word-Development-to-front-end-libraries

* fix/added-word-development-to-front-end-libraries-in-other-related-files

* fix/added-the-word-Development-to-front-end-and-all-related-files

* fix/removed-typos-from-last-commit-in-index.md

* fix/reverted-changes-that-i-made-to-dependecies

* fix/removed xvfg

* fix/reverted changes that i made to package.json

* remove unwanted changes

* front-end-development-libraries changes

* rename backend certSlug and README

* update i18n folder names and keys

* test: add legacy path redirect tests

This uses serve.json from the client-config repo, since we currently use
that in production

* fix: create public dir before moving serve.json

* fix: add missing script

* refactor: collect redirect tests

* test: convert to cy.location for stricter tests

* rename certificate folder to 00-certificates

* change crowdin config to recognise new certificates location

* allow translations to be used

Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>

* add forwards slashes to path redirects

* fix cypress path tests again

* plese cypress

* fix: test different challenge

Okay so I literally have no idea why this one particular challenge
fails in Cypress Firefox ONLY. Tom and I paired and spun a full build
instance and confirmed in Firefox the page loads and redirects as
expected. Changing to another bootstrap challenge passes Cypress firefox
locally. Absolutely boggled by this.

AAAAAAAAAAAAAAA

* fix: separate the test

Okay apparently the test does not work unless we separate it into
a different `it` statement.

>:( >:( >:( >:(

Co-authored-by: Sujal Gupta <55016909+heysujal@users.noreply.github.com>
Co-authored-by: Noor Fakhry <65724923+NoorFakhry@users.noreply.github.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
This commit is contained in:
Shaun Hamilton
2021-08-14 03:57:13 +01:00
committed by GitHub
parent 4df2a0c542
commit c2a11ad00d
1215 changed files with 790 additions and 449 deletions

View File

@ -0,0 +1,131 @@
---
id: 564944c91be2204b269d51e3
title: 使用 jQuery 更改元素內部的文本
challengeType: 6
forumTopicId: 16773
dashedName: change-text-inside-an-element-using-jquery
---
# --description--
可以通過 jQuery 改變元素開始和結束標籤之間的文本。 甚至改變 HTML 標籤。
jQuery 有一個 `.html()` 函數,能用其在標籤裏添加 HTML 標籤和文本, 函數提供的內容將完全替換之前標籤的內容。
下面是重寫並強調標題文本的代碼:
```js
$("h3").html("<em>jQuery Playground</em>");
```
jQuery 還有一個類似的函數 `.text()`,可以在不添加標籤的前提下改變標籤內的文本。 換句話說,這個函數不會評估傳遞給它的任何 HTML 標記,而是將其視爲要替換現有內容的文本。
給 id 爲 `target4` 的按鈕的文本添加強調效果。
查看這篇[關於 &lt;em> 的文章](https://www.freecodecamp.org/news/html-elements-explained-what-are-html-tags/#em-element)來了解更多 `<i>``<em>` 的區別和用法。
注意,`<i>` 標籤雖然傳統上用來強調文本,但此後常用作圖標的標籤。 `<em>` 標籤作爲強調標籤現在已被廣泛接受。 可以使用任意一種完成這個挑戰。
# --hints--
應該通過添加 HTML 標籤強調 `target4` 按鈕中的文本。
```js
assert.isTrue(
/<em>|<i>\s*#target4\s*<\/em>|<\/i>/gi.test($('#target4').html())
);
```
文本應該保持不變。
```js
assert($('#target4') && $('#target4').text().trim() === '#target4');
```
不應該改變其它任何文本內容。
```js
assert.isFalse(/<em>|<i>/gi.test($('h3').html()));
```
應該使用 `.html()` 方法而不是 `.text()` 方法。
```js
assert(code.match(/\.html\(/g));
```
應該使用 jQuery 選取 `button id="target4"`
```js
assert(code.match(/\$\(\s*?(\"|\')#target4(\"|\')\s*?\)\.html\(/));
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target4").html('<em>#target4</em>');
});
</script>
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,119 @@
---
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
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
$(".well").addClass("animated shake");
$("#target3").addClass("animated fadeOut");
$("button").removeClass("btn-default");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
$(".well").addClass("animated shake");
$("#target3").addClass("animated fadeOut");
$("button").removeClass("btn-default");
$("#target1").css("color", "red");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,121 @@
---
id: bad87fee1348bd9aed508826
title: 使用 jQuery 克隆元素
challengeType: 6
forumTopicId: 16780
dashedName: clone-an-element-using-jquery
---
# --description--
除了移動標籤,也可以把元素從一個地方複製到另一地方。
jQuery 有一個 `clone()` 方法,可以複製標籤。
例如,如果想把 `target2``left-well` 複製到 `right-well`,可以設置如下:
```js
$("#target2").clone().appendTo("#right-well");
```
是否注意到這兩個 jQuery 函數連在一起了? 這被稱爲<dfn>鏈式調用function chaining</dfn>,是一種用 jQuery 實現效果的簡便方法。
克隆 `target5` 元素,並將其附加到 `left-well`
# --hints--
`target5` 元素應該在 `right-well` 裏面。
```js
assert($('#right-well').children('#target5').length > 0);
```
應該克隆 `target5` 元素,並放在 `left-well` 裏面。
```js
assert($('#left-well').children('#target5').length > 0);
```
應該僅用 jQuery 移動這些元素。
```js
assert(!code.match(/class.*animated/g));
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,125 @@
---
id: bad87fee1348bd9aeda08726
title: 刪除 jQuery 函數
challengeType: 6
forumTopicId: 17561
required:
-
link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css'
dashedName: delete-your-jquery-functions
---
# --description--
這些動畫開始看起來很酷,但是有時可能會讓用戶分心。
請刪除 `document ready function` 內的三個 jQuery 函數,但保留 `document ready function` 本身。
# --hints--
應該刪除 `document ready function` 中的三個 jQuery 函數。
```js
assert(code.match(/\{\s*\}\);/g));
```
應該保持 `script` 標籤不變。
```js
assert(code.match(/<script>/g));
```
應該保持 `$(document).ready(function() {``script` 標籤的開頭不變。
```js
assert(code.match(/\$\(document\)\.ready\(function\(\)\s?\{/g));
```
應該保持 `document.ready` function 用 `})` 閉合。
```js
assert(code.match(/.*\s*\}\);/g));
```
應該保持 `script` 標籤閉合。
```js
assert(
code.match(/<\/script>/g) &&
code.match(/<script/g) &&
code.match(/<\/script>/g).length === code.match(/<script/g).length
);
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
$(".well").addClass("animated shake");
$("#target3").addClass("animated fadeOut");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,120 @@
---
id: bad87fee1348bd9aed808826
title: 使用 jQuery 禁用元素
challengeType: 6
forumTopicId: 17563
dashedName: disable-an-element-using-jquery
---
# --description--
還能用 jQuery 改變 HTML 標籤的非 CSS 屬性, 例如:禁用按鈕。
當禁用按鈕時,它將變成灰色並無法點擊。
jQuery 有一個 `.prop()` 方法,可以用其調整標籤的屬性。
下面是禁用所有的按鈕的代碼:
```js
$("button").prop("disabled", true);
```
僅禁用 `target1` 按鈕。
# --hints--
`target1` 按鈕應該被禁用。
```js
assert(
$('#target1') &&
$('#target1').prop('disabled') &&
code.match(/["']disabled["'],( true|true)/g)
);
```
不應該禁用其它的按鈕。
```js
assert($('#target2') && !$('#target2').prop('disabled'));
```
應該僅用 jQuery 給元素添加這些 class。
```js
assert(!code.match(/disabled[^<]*>/g));
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,118 @@
---
id: bad87fee1348bd9acdd08826
title: 瞭解 script 和 document.ready 是如何工作的
challengeType: 6
forumTopicId: 18224
dashedName: learn-how-script-tags-and-document-ready-work
---
# --description--
馬上就要學習有史以來最受歡迎的 JavaScript 框架——jQuery 了。
在使用 jQuery 之前,需要在 HTML 頁面中添加一些東西。
首先,在頁面頂部添加 `script` 標籤, 記得在後面爲它添加結束標籤。
瀏覽器會運行 `script` 標籤所有的 JavaScript 腳本包括 jQuery。
`script` 標籤中添加代碼 `$(document).ready(function() {`。 然後在後面(仍在該 `script` 標籤內)用 `});` 閉合它。
稍後將詳細介紹 `functions` 現在需要知道的是,只要瀏覽器加載頁面,`function` 中放入的代碼就會運行。
有一點很重要,如果沒有 `document ready function`,代碼將在 HTML 頁面呈現之前運行,這可能會導致錯誤。
# --hints--
應該創建一個 `script` 標籤,確保其有效並具有閉合標籤。
```js
assert(
code.match(/<\/script\s*>/g) &&
code.match(
/<script(\sasync|\sdefer)*(\s(charset|src|type)\s*=\s*["\"]+[^"\"]*["\"]+)*(\sasync|\sdefer)*\s*>/g
) &&
code.match(/<\/script\s*>/g).length ===
code.match(
/<script(\sasync|\sdefer)*(\s(charset|src|type)\s*=\s*["\"]+[^"\"]*["\"]+)*(\sasync|\sdefer)*\s*>/g
).length
);
```
應該在 `script` 的開頭添加 `$(document).ready(function() {`
```js
assert(
code.match(
/\$\s*?\(\s*?document\s*?\)\.ready\s*?\(\s*?function\s*?\(\s*?\)\s*?\{/g
)
);
```
應該用 `});` 閉合 `$(document).ready(function() {` 函數。
```js
assert(code.match(/\n*?\s*?\}\s*?\);/g));
```
# --seed--
## --seed-contents--
```html
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,109 @@
---
id: bad87fee1348bd9aed708826
title: 使用 jQuery 刪除元素
challengeType: 6
forumTopicId: 18262
dashedName: remove-an-element-using-jquery
---
# --description--
現在學習用 jQuery 從頁面移除 HTML 標籤。
jQuery 有一個 `.remove()` 方法,能完全移除 HTML 標籤。
`.remove()` 方法從頁面移除 `#target4` 元素。
# --hints--
應該用 jQuery 從頁面中移除 `target4`標籤。
```js
assert(
$('#target4').length === 0 && code.match(/\$\(["']#target4["']\).remove\(\)/g)
);
```
應該僅用 jQuery 移除該標籤。
```js
assert(
code.match(/id="target4/g) &&
!code.match(/<!--.*id="target4".*-->/g) &&
$('#right-well').length > 0
);
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,122 @@
---
id: bad87fee1348bd9aed918626
title: 使用 jQuery 從元素中移除 class
challengeType: 6
forumTopicId: 18264
required:
-
link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css'
dashedName: remove-classes-from-an-element-with-jquery
---
# --description--
和用 jQuery 的 `addClass()` 方法給標籤添加類一樣,也可以利用 jQuery 的 `removeClass()` 方法移除它們。
下面是爲指定按鈕執行上面的操作的代碼:
```js
$("#target2").removeClass("btn-default");
```
請把所有 `button` 元素的 `btn-default` class 移除。
# --hints--
應該移除所有 `button` 元素 `btn-default` class。
```js
assert($('.btn-default').length === 0);
```
應該僅用 jQuery 從元素中移除 class。
```js
assert(code.match(/btn btn-default/g));
```
應該僅移除 `btn-default` class。
```js
assert(
code.match(
/\.[\v\s]*removeClass[\s\v]*\([\s\v]*('|")\s*btn-default\s*('|")[\s\v]*\)/gm
)
);
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
$(".well").addClass("animated shake");
$("#target3").addClass("animated fadeOut");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
$(".well").addClass("animated shake");
$("#target3").addClass("animated fadeOut");
$("button").removeClass("btn-default");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,144 @@
---
id: bad87fee1348bd9aed108826
title: 使用 jQuery 選擇元素的特定子元素
challengeType: 6
forumTopicId: 18315
required:
-
link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css'
dashedName: target-a-specific-child-of-an-element-using-jquery
---
# --description--
已經看到了 id 屬性對於 jQuery 選擇器選取標籤的便利, 但這並不適用於所有情景。
幸運的是jQuery 有一些其他的方法可以選取正確的標籤。
jQuery 可以用 CSS 選擇器CSS Selectors選取標籤。 `target:nth-child(n)` CSS 選擇器可以選取指定 class 或者元素類型的的第 n 個標籤。
下面的代碼展示了給每個區域well的第 3 個標籤設置彈跳bounce動畫效果
```js
$(".target:nth-child(3)").addClass("animated bounce");
```
給 well 元素的第二個子元素添加彈跳bounce動畫效果。 你必須選擇具有 `target` class 的元素子項。
# --hints--
`target` 元素中的第二個元素應該有彈跳bounce動畫效果。
```js
assert(
$('.target:nth-child(2)').hasClass('animated') &&
$('.target:nth-child(2)').hasClass('bounce')
);
```
應該僅兩個元素有彈跳bounce動畫效果。
```js
assert($('.animated.bounce').length === 2);
```
你應該使用 `:nth-child()` 選擇器修改這些元素。
```js
assert(code.match(/\:nth-child\(/g));
```
應該僅用 jQuery 給元素添加 class。
```js
assert(
code.match(/\$\(".target:nth-child\(2\)"\)/g) ||
code.match(/\$\('.target:nth-child\(2\)'\)/g) ||
code.match(/\$\(".target"\).filter\(":nth-child\(2\)"\)/g) ||
code.match(/\$\('.target'\).filter\(':nth-child\(2\)'\)/g)
);
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
$("#target1").parent().css("background-color", "red");
$("#right-well").children().css("color", "orange");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
$("#target1").parent().css("background-color", "red");
$("#right-well").children().css("color", "orange");
$(".target:nth-child(2)").addClass("animated bounce");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,113 @@
---
id: bad87fee1348bd9aedc08826
title: 使用 jQuery class 選擇器選擇元素
challengeType: 6
forumTopicId: 18316
required:
-
link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css'
dashedName: target-elements-by-class-using-jquery
---
# --description--
如何使所有的 `button` 標籤都有彈跳的動畫效果? 用 `$("button")` 選取所有的 button 標籤,並用 `.addClass("animated bounce");` 給其添加一些 CSS 屬性。
jQuery 的 `.addClass()` 方法用來給標籤添加類。
首先,使用 `$(".well")` 選取類爲 `well``div` 標籤。
值得注意的是,和 CSS 聲明一樣,在類名前需要添加 `.`
然後,用 jQuery 的 `.addClass()` 方法添加 `animated``shake` class。
例如,在 `document ready function` 中添加下面的代碼,使所有類爲 `text-primary` 的標籤抖動:
```js
$(".text-primary").addClass("animated shake");
```
# --hints--
應該用 jQuery 的 `addClass()` 方法給所有 class 爲 `well` 的元素添加 `animated``shake` class。
```js
assert($('.well').hasClass('animated') && $('.well').hasClass('shake'));
```
應該僅用 jQuery 給元素添加這些 class。
```js
assert(!code.match(/class\.\*animated/g));
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
$(".well").addClass("animated shake");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,123 @@
---
id: bad87fee1348bd9aeda08826
title: 使用 jQuery id 選擇器選擇元素
challengeType: 6
forumTopicId: 18317
required:
-
link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css'
dashedName: target-elements-by-id-using-jquery
---
# --description--
也能通過 id 屬性選取標籤。
首先,用 `$("#target3")` 選擇器選取 id 爲 `target3``button` 標籤。
注意,和 CSS 聲明一樣,在 id 名前需要添加 `#`
然後,用 jQuery 的 `.addClass()` 方法添加 `animated``fadeOut` 類。
下面的代碼的效果是使 id 爲 `target6``button` 標籤淡出:
```js
$("#target6").addClass("animated fadeOut");
```
# --hints--
應該選擇 `id``target3``button` 元素,使用 jQuery 的 `addClass()` 函數給它添加 `animated` class。
```js
assert($('#target3').hasClass('animated'));
```
應該選中 id 爲 `target3` 的元素,使用 jQuery 的 `addClass()` 函數給它添加 `fadeOut` class。
```js
assert(
($('#target3').hasClass('fadeOut') || $('#target3').hasClass('fadeout')) &&
code.match(/\$\(\s*.#target3.\s*\)/g)
);
```
應該僅用 jQuery 給元素添加這些 class。
```js
assert(!code.match(/class.*animated/g));
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
$(".well").addClass("animated shake");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
$(".well").addClass("animated shake");
$("#target3").addClass("animated fadeOut");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,139 @@
---
id: bad87fee1348bd9aed008826
title: 使用 jQuery 選擇偶數元素
challengeType: 6
forumTopicId: 18318
required:
-
link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css'
dashedName: target-even-elements-using-jquery
---
# --description--
也可以用基於位置的奇 `:odd` 和偶 `:even` 選擇器選取標籤。
注意jQuery 是零索引zero-indexed這意味着第 1 個標籤的位置編號是 0。 這有點混亂和反常——`:odd` 表示選擇第 2 個標籤(位置編號 1第 4 個標籤(位置編號 3……等等以此類推。
下面的代碼展示了選取所有 `target` class 元素的奇數元素並設置 sheke 效果:
```js
$(".target:odd").addClass("animated shake");
```
嘗試選取所有 `target` class 元素的偶數元素並給它們設置 `animated``shake` class。 請記住, **偶數**指的是基於零系統的元素的位置。
# --hints--
所有的偶數位置上的 `target` 元素都應該抖動。
```js
assert(
$('.target:even').hasClass('animated') && $('.target:even').hasClass('shake')
);
```
應該使用 `:even` 選擇器修改這些元素。
```js
assert(code.match(/\:even/g));
```
應該僅用 jQuery 給元素添加 class。
```js
assert(
code.match(/\$\(".target:even"\)/g) ||
code.match(/\$\('.target:even'\)/g) ||
code.match(/\$\(".target"\).filter\(":even"\)/g) ||
code.match(/\$\('.target'\).filter\(':even'\)/g)
);
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
$("#target1").parent().css("background-color", "red");
$("#right-well").children().css("color", "orange");
$("#left-well").children().css("color", "green");
$(".target:nth-child(2)").addClass("animated bounce");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
$("#target1").parent().css("background-color", "red");
$("#right-well").children().css("color", "orange");
$("#left-well").children().css("color", "green");
$(".target:nth-child(2)").addClass("animated bounce");
$(".target:even").addClass("animated shake");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,118 @@
---
id: bad87fee1348bd9bedc08826
title: 使用 jQuery 選擇器選擇元素
challengeType: 6
forumTopicId: 18319
required:
-
link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css'
dashedName: target-html-elements-with-selectors-using-jquery
---
# --description--
現在我們有一個 `document ready` 函數。
首先,完成第一個 jQuery 語句。 所有的 jQuery 函數都以 `$` 開頭這個符號通常被稱爲美元符號dollar sign operator或 bling。
jQuery 通常選取並操作帶有<dfn>選擇器selector</dfn>的 HTML 標籤。
比如,想要給 `button` 元素添加跳躍效果。 只需要在 document ready 函數內添加如下代碼:
```js
$("button").addClass("animated bounce");
```
請注意,我們已經在後臺引入了 jQuery 庫和 Animate.css 庫,所以你可以在編輯器裏直接使用它們。 你將使用 jQuery 將 Animate.css `bounce` class 應用於 `button` 元素。
# --hints--
應該用 jQuery 的 `addClass()` 函數給 `button` 元素添加 `animated``bounce` class。
```js
assert($('button').hasClass('animated') && $('button').hasClass('bounce'));
```
應該僅用 jQuery 給元素添加 class。
```js
assert(!code.match(/class.*animated/g));
```
jQuery 代碼應該放在 `$(document).ready();` 函數裏。
```js
assert(
code.replace(/\s/g, '').match(/\$\(document\)\.ready\(function\(\)\{\$/g)
);
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,125 @@
---
id: bad87fee1348bd9aed208826
title: 使用 jQuery 選擇元素的子元素
challengeType: 6
forumTopicId: 18320
dashedName: target-the-children-of-an-element-using-jquery
---
# --description--
把 HTML 標籤放到另一個級別的標籤裏,這些 HTML 標籤被稱爲該標籤的<dfn>子標籤children element</dfn>。 例如,本次挑戰中文本爲 `#target1``#target2``#target3` 的按鈕都是 `<div class="well" id="left-well">` 標籤的子標籤。
jQuery 有一個 `children()` 方法,可以訪問被選取標籤的子標籤。
下面的代碼展示了用 `children()` 方法把 `left-well` 標籤的子標籤的顏色設置成 `blue`(藍色):
```js
$("#left-well").children().css("color", "blue")
```
# --instructions--
`right-well` 元素的所有子元素設置爲橙色orange
# --hints--
`#right-well` 的所有子元素應該有橙色文本。
```js
assert($('#right-well').children().css('color') === 'rgb(255, 165, 0)');
```
應該用 `children()` 函數修改這些元素。
```js
assert(code.match(/\.children\(\)\.css/g));
```
應該僅用 jQuery 給標籤添加 class。
```js
assert(code.match(/<div class="well" id="right-well">/g));
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
$("#target1").parent().css("background-color", "red");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
$("#target1").parent().css("background-color", "red");
$("#right-well").children().css("color", "orange");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,140 @@
---
id: bad87fee1348bd9aed308826
title: 使用 jQuery 選擇元素的父元素
challengeType: 6
forumTopicId: 18321
dashedName: target-the-parent-of-an-element-using-jquery
---
# --description--
每個 HTML 標籤都默認 `inherits`(繼承)其 `parent`(父標籤)的 CSS 屬性。
例如,`h3` 標籤 `jQuery Playground` 的父標籤是 `<div class="container-fluid">`,而這個標籤的父標籤是 `body`
jQuery 有一個 `parent()` 方法,可以訪問被選取標籤的父標籤。
下面的代碼展示了使用 `parent()` 方法把 `left-well` 標籤的父標籤背景色設置成藍色blue
```js
$("#left-well").parent().css("background-color", "blue")
```
`#target1` 元素的父元素背景色設置成紅色red
# --hints--
`left-well` 元素應該有紅色的背景。
```js
assert(
$('#left-well').css('background-color') === 'red' ||
$('#left-well').css('background-color') === 'rgb(255, 0, 0)' ||
$('#left-well').css('background-color').toLowerCase() === '#ff0000' ||
$('#left-well').css('background-color').toLowerCase() === '#f00'
);
```
應該用 `.parent()` 函數修改該元素。
```js
assert(code.match(/\.parent\s*\(\s*\)\s*\.css/g));
```
應該在 `#target1` 元素上調用 `.parent()` 方法。
```js
assert(
code.match(/\$\s*?\(\s*?(?:'|")\s*?#target1\s*?(?:'|")\s*?\)\s*?\.parent/gi)
);
```
應該僅用 jQuery 給元素添加 class。
```js
assert(code.match(/<div class="well" id="left-well">/g));
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
});
</script>
<!-- Only change code above this line -->
<body>
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
</body>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
$("#target1").parent().css("background-color", "red");
});
</script>
<!-- Only change code above this line -->
<body>
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
</body>
```

View File

@ -0,0 +1,143 @@
---
id: bad87fee1348bd9aed908626
title: 用多個 jQuery 選擇器選擇同一個元素
challengeType: 6
forumTopicId: 18322
required:
-
link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css'
dashedName: target-the-same-element-with-multiple-jquery-selectors
---
# --description--
現在學寫了三種選取標籤的方法:用標籤選擇器: `$("button")`,用類選擇器:`$(".btn")` 以及用 id 選擇器:`$("#target1")`
雖然可以在單個 `.addClass()` 內添加多個類,但是我們可以用*三種不同的方式*給一種標籤添加類。
以三種不同的方式用 `.addClass()` 方法每次只給一種標籤添加一個類:
給所有的 `button` 標籤添加 `animated` 類。
給所有類爲 `.btn` 的 button 標籤添加 `shake` 類。
給所有 id 爲 `#target1` 的 button 標籤添加 `btn-primary` 類。
**注意:**只針對一個元素並且一次只能添加一個 class。 總之,三個選擇器最終將添加三個 class `shake``animated` 以及 `btn-primary``#target1` 上。
# --hints--
應該使用 `$("button")` 選擇器。
```js
assert(code.match(/\$\s*?\(\s*?(?:'|")\s*?button\s*?(?:'|")/gi));
```
應該使用 `$(".btn")` 選擇器。
```js
assert(code.match(/\$\s*?\(\s*?(?:'|")\s*?\.btn\s*?(?:'|")/gi));
```
應該使用 `$("#target1")` 選擇器。
```js
assert(code.match(/\$\s*?\(\s*?(?:'|")\s*?#target1\s*?(?:'|")/gi));
```
三個選擇器每個應該只添加一個類。
```js
assert(
code.match(/addClass/g) &&
code.match(/addClass\s*?\(\s*?('|")\s*?[\w-]+\s*?\1\s*?\)/g).length > 2
);
```
`#target1` 標籤應具有 `animated``shake``btn-primary` 三個類。
```js
assert(
$('#target1').hasClass('animated') &&
$('#target1').hasClass('shake') &&
$('#target1').hasClass('btn-primary')
);
```
應該僅用 jQuery 給標籤添加類。
```js
assert(!code.match(/class.*animated/g));
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("button").addClass("animated");
$(".btn").addClass("shake");
$("#target1").addClass("btn-primary");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,117 @@
---
id: bad87fee1348bd9aed608826
title: 使用 jQuery 的 appendTo 方法移動元素
challengeType: 6
forumTopicId: 18340
dashedName: use-appendto-to-move-elements-with-jquery
---
# --description--
現在來把標籤從一個 `div` 移動到另一個裏。
jQuery 有一個 `appendTo()` 方法,可以選取 HTML 標籤並將其添加到另一個標籤裏面。
例如,如果要把 `target4` 從 right well 移到 left well可以設置如下
```js
$("#target4").appendTo("#left-well");
```
`target2` 元素從 `left-well` 移動到 `right-well`
# --hints--
`target2` 元素不應該在 `left-well` 內。
```js
assert($('#left-well').children('#target2').length === 0);
```
`target2` 元素應該在 `right-well` 內。
```js
assert($('#right-well').children('#target2').length > 0);
```
應該僅用 jQuery 移動這些標籤。
```js
assert(!code.match(/class.*animated/g));
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```

View File

@ -0,0 +1,118 @@
---
id: bad87fee1348bd9aecb08826
title: 使用 jQuery 修改整個頁面
challengeType: 6
forumTopicId: 18361
required:
-
link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css'
dashedName: use-jquery-to-modify-the-entire-page
---
# --description--
目前,已經完成了 jQuery playground。 把它移除吧。
jQuery 也能選取 `body` 標籤。
這是使整個 body 淡出的代碼:`$("body").addClass("animated fadeOut");`
來做一些更好玩的事。 給 `body` 標籤添加 `animated``hinge` class。
# --hints--
應該給 `body` 標籤添加 `animated``hinge` class。
```js
assert($('body').hasClass('animated') && $('body').hasClass('hinge'));
```
# --seed--
## --seed-contents--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
$("#target1").parent().css("background-color", "red");
$("#right-well").children().css("color", "orange");
$("#left-well").children().css("color", "green");
$(".target:nth-child(2)").addClass("animated bounce");
$(".target:even").addClass("animated shake");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
$("#target1").parent().css("background-color", "red");
$("#right-well").children().css("color", "orange");
$("#left-well").children().css("color", "green");
$(".target:nth-child(2)").addClass("animated bounce");
$(".target:even").addClass("animated shake");
$("body").addClass("animated hinge");
});
</script>
<!-- Only change code above this line -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
```