--- id: bad87fee1348bd9aed908626 title: Target the Same Element with Multiple jQuery Selectors required: - link: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css' challengeType: 6 forumTopicId: 18322 localeTitle: 用多个 jQuery 选择器选择同一个元素 --- ## Description
现在你知道三种选取标签的方法:用标签选择器,如$("button");用类选择器,$(".btn")以及用 id 选择器,$("#target1")。 虽然可以在单个.addClass()内添加多个类,但是我们可以用三种不同的方式给一种标签添加类。 以三种不同的方式用.addClass()方法每次只给一种标签添加一个类: 给所有的button标签添加animated类。 给所有类为.btnbutton标签添加shake类。 给所有 id 为#target1button标签添加btn-primary类。 注意:
虽然三个选择器最终给 id 为#target1button标签添加shakeanimatedbtn-primary等三个类,但是你需要用且仅用三种不同的选择器给三种标签各添加一个类(译者注:所谓的“一种标签”是指他们有某种共同的特点,如包含同一个 class)。
## Instructions
## Tests
```yml tests: - text: "用$('button')选择标签。" testString: assert(code.match(/\$\s*?\(\s*?(?:'|")\s*?button\s*?(?:'|")/gi)); - text: "用$('.btn')选择标签。" testString: assert(code.match(/\$\s*?\(\s*?(?:'|")\s*?\.btn\s*?(?:'|")/gi)); - text: "用$('#target1')选择标签。" testString: assert(code.match(/\$\s*?\(\s*?(?:'|")\s*?#target1\s*?(?:'|")/gi)); - text: 三个选择器每个只添加一个类。 testString: assert(code.match(/addClass/g) && code.match(/addClass\s*?\(\s*?('|")\s*?[\w-]+\s*?\1\s*?\)/g).length > 2); - text: #target1标签应具有animatedshakebtn-primary三个类。 testString: assert($('#target1').hasClass('animated') && $('#target1').hasClass('shake') && $('#target1').hasClass('btn-primary')); - text: 仅用 jQuery 给标签添加类。 testString: assert(!code.match(/class.*animated/g)); ```
## Challenge Seed
```html

jQuery Playground

#left-well

#right-well

```
## Solution
```html

jQuery Playground

#left-well

#right-well

```