I select some paragraphs inside a div:
$('#myDiv p.p1, #myDiv p.p2').text();
My problem is that I want to add space between each selection so that the output is: “paragraph1 (space) paragraph2” instead of “paragraph1paragraph2”.
Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
.map()with.get()to create an array of the separate paragraphs, then use.join(" ")to join them together with a space in between.Try this:
The
resultvariable should have your paragraphs with a space separating them.EDIT: Based on comment from @J-P, updated the text retrieval to be more efficient.