user269431
user269431

Reputation: 155

Read li values and insert them in an array?

I have a ul with id ul1. In the UL I have 3 li, each containing a textbox. How do I read each and every li of the ul to retrieve the values of the textbox in the li and put them in an array?

Upvotes: 2

Views: 1891

Answers (2)

Artem Barger
Artem Barger

Reputation: 41222

Should be enough

 var values = $( "#ul1 textarea").map( function( )
 { 
       return $(this).val( );
 }).get( );

Upvotes: 4

Tatu Ulmanen
Tatu Ulmanen

Reputation: 124768

It's as simple as this:

var values = [];

$('#ul1 li textarea').each(function() {
    values.push($(this).val());
});

Upvotes: 5

Related Questions