Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery select multiple <p> in <div>

HTML:

<div id='example'>
  <p> First paragraph</p>
  <p> Second paragraph</p>
  <p> Third paragraph</p>
</div>

Javascript with JQuery: var paragraphs = $('div#examples p');

This returns an array of HTMLParagraphElement objects. However, I wish to return Jquery objects. (So that I can use e.g:

for(i=0;i<paragraphs.length;i++)
{
   paragraph[i].hide();
}

Is there a way I can easily do this? Thanks.

like image 273
whamsicore Avatar asked Mar 09 '11 05:03

whamsicore


People also ask

What does div P Select in jQuery?

Description. "$("div p")" Selects all elements matched by <div> that contain an element matched by <p>.

Can you select multiple elements in jQuery?

Definition and Usage. The element selector can also be used to select multiple elements. Note: Seperate each element with a comma.

How do I get paragraph text in jQuery?

You can simply use the jQuery text() method to get all the text content inside an element. The text() method also return the text content of child elements.


1 Answers

example:

$('#examples p').hide();

div is not necessary

like image 61
xuesong Avatar answered Sep 28 '22 09:09

xuesong