[英]jquery p:last-child not working
I'm trying to add some data to my paragraphs, how ever it is only working for my first p
. 我试图将一些数据添加到段落中,但是它仅适用于我的第一个p
。
I can make it put the data into my last p
by using p:gt(0)
but seems like I should be able to use p:last-child
. 我可以使用p:gt(0)
使其将数据放入最后一个p
,但似乎我应该可以使用p:last-child
。
Any idea where I'm going wrong? 知道我哪里出错了吗?
HTML 的HTML
<div class="col-md-12" id="quizEnd" style="display:none;text-align:center;">
<p></p>
<p></p>
<h2></h2>
</div>
JS: JS:
$("#quizEnd p:first-child").text("Navn : " + quizName);
$("#quizEnd p:last-child").text("Email : " + quizMail);
It's because that p
element isn't the last child. 这是因为p
元素不是最后一个子元素。 The h2
elements is. h2
元素是。
You could use :last-of-type
instead: 您可以改用:last-of-type
:
$("#quizEnd p:last-of-type").text("Email : " + quizMail);
You could also use the .last()
method or the jQuery :last
selector: 您还可以使用.last()
方法或jQuery :last
选择器:
$("#quizEnd p:last").text("Email : " + quizMail);
$("#quizEnd p").last().text("Email : " + quizMail);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.