Delimiting a text string with jQuery

前端 未结 1 1275
孤街浪徒
孤街浪徒 2020-12-20 08:50

I am collecting the text from several elements like this:-

$(\'#element\').find(\'p\').text();

However this returns the text of all the \'p

相关标签:
1条回答
  • 2020-12-20 09:07

    You are right about using .map along with .join.

    Try something like this:

    var names = $('#element').find('p').map(function(){
       return $(this).text();
    }).get().join(',');
    console.log(names); //The Beatles,Radiohead,Britney Spears
    
    0 讨论(0)
提交回复
热议问题