Reputation: 11756
I'm able to get the list ID but not the value...what am I doing wrong?
My Code:
$('#listParams ').append('<li id="1">Item 1</li>');
$('#listParams ').append('<li id="2">Item 2</li>');
var items = "";
var lis = $("#listParams li");
for(var no=0;no<lis.length;no++){
if(items.length > 0) {
items = items + "|";
}
//items = items + lis[no].id + '-|-' + lis[no].text;
items = items + lis[no].id + '-|-' + lis[no].val;
}
alert(items);
Upvotes: 0
Views: 134
Reputation: 253485
One easier approach is to use map()
:
var itemsAndValues = $('#listParams li').map(
function(){
return this.id + ':' + $(this).text();
}).get().join(',');
Upvotes: 0
Reputation: 9402
Its an <li>
element so you need to get the innerHTML , not the value.
alert($("li#1").html());
Upvotes: 0
Reputation: 175956
How about
var items = [];
$("#listParams li").each(function() {
items.push(this.id + "-|-" + $(this).text());
});
alert(items.join());
Upvotes: 1