/ Published in: jQuery
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** v0.1 - 20081028 - thanks to Christian Oudard & Shog9 on StackOverflow - http://bit.ly/aqEKhO v0.2 - 201007100030 - brandonjp **/ /** specify an element, then collect the contents from each one on the page then concatenate all those contents and display them in one list/string **/ // first, a variable for the element we want to collect var theElements = $("td.fonta"); // second, a variable for the separater we want between each // by default the 'join()' method returns comma separated values var betweenEach = ""; // create the empty array where we'll store everything var allCurries = []; // now we actually get the elements we want and for each theElements.each(function() { // grab our array and push each element's text() into it allCurries.push( $(this).text() ); }); // create a new object that joins everything in our array var allTogether = allCurries.join(betweenEach); // inject, print, show, alert or display our final list $('div#output').replaceWith(allTogether); /** or the short version **/ var arr = []; $('td').each(function() { arr.push($(this).text()); }); alert(arr.join(''));