How to save value of an element selected by the array style in jQuery ?

Posted by Devyn on Stack Overflow See other posts from Stack Overflow or by Devyn
Published on 2010-03-23T01:07:55Z Indexed on 2010/03/23 1:11 UTC
Read the original article Hit count: 250

Filed under:

Let's say we have following this:

<p class="first">This is paragraph 1.</p> 
<p class="second">This is paragraph 2.</p> 
<p id="third">This is paragraph 3.</p>
<p>This is paragraph 4.</p>

We can save the value of an element in value variable and show like this.

var value = $('p').slice(3,4);
value.text(); // result --> This is paragraph 4

Above way has no problem if we know the number of element but we'll get problem if we have a lot of elements and we want to do with looping. why I get error if I do like this?

$('p')[3].text();

What should I do if I want to loop and get values?

© Stack Overflow or respective owner

Related posts about jQuery