Use jQuery to collect join concatenate print display alert the contents value html text of each div li item span td cell in a pa


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /** v0.1 - 20081028 - thanks to Christian Oudard & Shog9 on StackOverflow - http://bit.ly/aqEKhO
  2. v0.2 - 201007100030 - brandonjp **/
  3.  
  4.  
  5. /** specify an element, then collect the contents from each one on the page
  6. then concatenate all those contents and display them in one list/string **/
  7.  
  8. // first, a variable for the element we want to collect
  9. var theElements = $("td.fonta");
  10.  
  11. // second, a variable for the separater we want between each
  12. // by default the 'join()' method returns comma separated values
  13. var betweenEach = "";
  14.  
  15. // create the empty array where we'll store everything
  16. var allCurries = [];
  17.  
  18. // now we actually get the elements we want and for each
  19. theElements.each(function() {
  20. // grab our array and push each element's text() into it
  21. allCurries.push( $(this).text() );
  22. });
  23.  
  24. // create a new object that joins everything in our array
  25. var allTogether = allCurries.join(betweenEach);
  26.  
  27. // inject, print, show, alert or display our final list
  28. $('div#output').replaceWith(allTogether);
  29.  
  30.  
  31.  
  32.  
  33.  
  34. /** or the short version **/
  35.  
  36. var arr = [];
  37. $('td').each(function() {
  38. arr.push($(this).text());
  39. });
  40. alert(arr.join(''));

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.