var contents = $.map($('.text'), function(el){return $(el).text()}); var a = contents.join(',');
var contents = []; $('a').map(function(i){ contents[i] = $(this).text() }); var a = contents.join(',');
<script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function(){ var a=[]; $('span.text').each(function(i){ a[i]=$(this).text(); }); a=a.join(",") alert(a) }); </script> <span class="text">1</span><br /> <span class="text-notext">adad</span><br /> <span class="text">2</span><br /> <span class="text-notext">adad</span><br /> <span class="text">3</span><br /> <span class="text">4</span>