--- id: bad87fee1348bd9aed308826 title: Target the Parent of an Element Using jQuery challengeType: 6 videoUrl: '' localeTitle: 使用jQuery定位元素的父级 --- ## Description
每个HTML元素都有一个parent元素,它从中inherits属性。例如,您的jQuery Playground h3元素具有<div class="container-fluid">的父元素,它本身具有父body 。 jQuery有一个名为parent()的函数,允许您访问您选择的任何元素的父级。下面是一个如何使用parent()函数的例子,如果你想给left-well元素的父元素一个蓝色的背景颜色: $("#left-well").parent().css("background-color", "blue")#target1元素的父级#target1背景颜色为红色。
## 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", "Your left-well element should have a red background.");' - text: 您应该使用.parent()函数来修改此元素。 testString: 'assert(code.match(/\.parent\s*\(\s*\)\s*\.css/g), "You should use the .parent() function to modify this element.");' - text: '应该在#target1元素上调用.parent()方法。' testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?#target1\s*?(?:"|")\s*?\)\s*?\.parent/gi), "The .parent() method should be called on the #target1 element.");' - text: 只使用jQuery将这些类添加到元素中。 testString: 'assert(code.match(/
/g), "Only use jQuery to add these classes to the element.");' ```
## Challenge Seed
```html

jQuery Playground

#left-well

#right-well

```
## Solution
```js // solution required ```