I want to save selected items to an array.
for example:
var list = $('ul.theList li'),
result = $('div#result'); // other div
content;
for( var i=0; i < list.length; i++ ){
content[i] = $('ul.theList li')[i];
}
$(result).text(content); // the result
This doesnt work.
There’s two issues, first you’ve not defined the
contentas an array, and with that code you should probably define how the array-elements should be joined:JS Fiddle demo using
:eq()selector.JS Fiddle demo using
.eq()method.I’ve used
.push()to insert the text of theli(I’m assuming, here, that you want the text and not the node itself) to thecontentarray, rather than explicitly defining the index.References:
Array.push().:eq()selector..eq()method.