--- id: bad87fee1348bd9aed308826 challengeType: 6 forumTopicId: 18321 localeTitle: 使用 jQuery 选择元素的父元素 --- ## Description
每个 HTML 标签都默认继承(inherits)父标签(parent element)的 CSS 属性。 例如,h3标签jQuery Playground的父标签是<div class="container-fluid"><div class="container-fluid">的父标签是body。 jQuery 有一个parent()方法,可以访问被选取标签的父标签。 下面的代码展示了使用parent()方法把left-well标签的父标签背景色设置成蓝色(blue)的方式: $("#left-well").parent().css("background-color", "blue") 请把#target1标签的父标签背景色设置成红色(red)
## Instructions
## Tests
```yml tests: - text: left-well标签应该有红色的背景。 testString: 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'); - text: 应该用.parent()方法修改该标签。 testString: assert(code.match(/\.parent\s*\(\s*\)\s*\.css/g)); - text: 应该在#target1标签上调用.parent()方法。 testString: assert(code.match(/\$\s*?\(\s*?(?:'|")\s*?#target1\s*?(?:'|")\s*?\)\s*?\.parent/gi)); - text: 仅用 jQuery 给标签添加类。 testString: assert(code.match(/
/g)); ```
## Challenge Seed
```html

jQuery Playground

#left-well

#right-well

```
## Solution
```html

jQuery Playground

#left-well

#right-well

```