--- 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

jQuery Playground

#left-well

#right-well

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

jQuery Playground

#left-well

#right-well

```