我正在使用下面的代码来更改h3标记中最后一行文本的样式。我想要的是每个h3标签的最后一行颜色为红色。现在只有最后一个h3标签的最后一行颜色为红色。任何人都可以帮忙吗?通过jQuery或javascript更改最后一行的样式
$("h3").contents().last().wrap('<span id="lastLineTourTitle"></span>');
#lastLineTourTitle {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="product">
<h3>
This is a test<br>and this is the last line (1).
</h3>
</div>
<div class="product">
<h3>
This is a test<br>and this is the last line (2).
</h3>
</div>
<div class="product">
<h3>
This is a test<br>and this is the last line (3).
</h3>
</div>
</div>
如果你总是有2行,那么你可能会用':第一line'样式的第一行。不幸的是,没有“:最后一行”的等价物。 – GolezTrol