How would I select the first <p> element in the following <div> with jQuery?
<div>
<h1>heading</h1>
<p>How do I select this element with jQuery?</p>
<p>Another paragraph</p>
</div>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you have a reference to the
divalready:If the first
pwill always be a direct child of thediv, you could usechildreninstead offind.Some alternatives include:
Note that the
eqmethod will always be the fastest way to do this. Here’s the results of a quick comparison of theeqmethod,:eqselector and:firstselector (I didn’t bother with thefirstmethod since it’s just an alias ofeq(0)):