我有下一个 html 设置:
<div class="one">
<div class="two">
<a href="#" class="three">Click</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当我使用 jQuery单击元素.three时,我想更改类.one元素的背景颜色。
这就是我试图使用的:
$(function(){
$('.three')(function(){
$(this).parent().parent().css('backgroundColor', 'red');
})
});
Run Code Online (Sandbox Code Playgroud)
这是一个小提琴示例:https : //jsfiddle.net/Munja/a7unbs2p/
我在 SO 上在这里寻找解决方案,但无法足够快地找到它(可能我看起来不够好:/)。
谢谢你。
我用的时候
white-space: pre-line;
word-break: break-word;
Run Code Online (Sandbox Code Playgroud)
...在文本之前有一个加法行.为了隐藏它,我使用了:
.class:first-line { line-height: 0; }
Run Code Online (Sandbox Code Playgroud)
...它在Chrome浏览器中运行,但不在Firefox中.
这是一个工作小提琴,请在Firefox中打开它:https://jsfiddle.net/t3qj51co/2/