Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  19] [ 7]  / answers: 1 / hits: 17973  / 14 Years ago, wed, march 9, 2011, 12:00:00

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.


More From » jquery

 Answers
69

Thanks everybody for input. Iteration of the div p array was necessary (sorry if that wasn't clear), so doing $('div#example p').hide(); was not a proper solution. I ended up doing the following:



var arr = $('div#example p');

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


Hope this is useful for people in the future:)


[#93367] Monday, March 7, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
parker

Total Points: 259
Total Questions: 109
Total Answers: 97

Location: Zambia
Member since Thu, Jun 25, 2020
4 Years ago
;