CSS 选择器(CSS Selectors)
选取标签。target:nth-child(n)
CSS 选择器可以选取所有的第 n 个标签并设置目标属性和目标样式。
下面的代码展示了给每个区域(well)的第 3 个标签设置bounce
类:
$(".target:nth-child(3)").addClass("animated bounce");
请给每个区域(well)的第 2 个标签设置bounce
类,必须用target
类选取标签。
target
标签中的第二个标签应该有弹性的动画效果。
testString: assert($(".target:nth-child(2)").hasClass("animated") && $(".target:nth-child(2)").hasClass("bounce"));
- text: 应该仅两个标签有弹性的动画效果。
testString: assert($(".animated.bounce").length === 2);
- text: 应该用:nth-child()
选择器修改这些标签。
testString: assert(code.match(/\:nth-child\(/g));
- text: 仅用 jQuery 给标签添加类。
testString: 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));
```