parent
元素,它从中inherits
属性。例如,您的jQuery Playground
h3
元素具有<div class="container-fluid">
的父元素,它本身具有父body
。 jQuery有一个名为parent()
的函数,允许您访问您选择的任何元素的父级。下面是一个如何使用parent()
函数的例子,如果你想给left-well
元素的父元素一个蓝色的背景颜色: $("#left-well").parent().css("background-color", "blue")
为#target1
元素的父级#target1
背景颜色为红色。 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(/