选择< p>在使用jQuery的div中 [英] Selecting <p> within a div using jQuery

查看:65
本文介绍了选择< p>在使用jQuery的div中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择第二个<p>标签,并在itemize类div中对其进行样式设置.这是HTML示例:

I want to select the second <p> tag and style it within a itemize class div. Here is the example HTML:

<div class="itemize">
    <p> Order Summery</p>
    <div>
        <p><strong>Packages:</strong> </p> <!-- i want to select this P tag-->
        <p><strong>Date:</strong> </p>
        <p><strong>Style:</strong> </p>
    </div>
</div>

我想选择第二个<div>之后的第一个<p>并设置样式.第二个<p>没有ID或类.

I want to select and style the first <p> which is immediately after the second <div>. The second <p> has no ID or class.

如何通过jQuery选择它?

How can I select it via jQuery?

推荐答案

您可以这样做:

$('.itemize > div > p:eq(0)')

.itemize > div直到:

<div class="itemize">
    <p> Order Summery</p>
</div>

还有

.itemize > div > p:eq(0)

<div class="itemize">
    <p> Order Summery</p>
    <div>
        <p><strong>Packages:</strong> </p>
    </div>
</div>

>允许定位直接子级,而eq(index)用于获取所需的第一个p.

The > allows to target direct children whereas eq(index) is used to get first p that you want.

这篇关于选择&lt; p&gt;在使用jQuery的div中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆