Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  165] [ 4]  / answers: 1 / hits: 42593  / 12 Years ago, mon, june 18, 2012, 12:00:00

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>


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



How can I select it via jQuery?


More From » jquery

 Answers
8

You can do this way:



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


.itemize > div goes till:



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


And



.itemize > div > p:eq(0)



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


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


[#84841] Saturday, June 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mira

Total Points: 460
Total Questions: 108
Total Answers: 99

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
mira questions
;