Alex Rivera | Logout

What is Join() in jQuery?

Asked 2009-10-20T10:44:26.723
62

What is Join() in jquery? for example:

var newText = $("p").text().split(" ").join("</span> <span>"); 
Edit
Report

2 Answers

19

You would probably use your example like this

var newText = "<span>" + $("p").text().split(" ").join("</span> <span>") + "</span>";

This will put span tags around all the words in you paragraphs, turning

<p>Test is a demo.</p>

into

<p><span>Test</span> <span>is</span> <span>a</span> <span>demo.</span></p>

I do not know what the practical use of this could be.

answered 2009-10-20T10:50:47.163
1

A practical example using a jQuery example might be

 var today = new Date();
 $('#'+[today.getMonth()+1, today.getDate(), today.getFullYear()].join("_")).whatever();

I do that in a calendar tool that I am using, this way on the page load, I can do certain things with today's date.

answered 2010-01-25T20:35:41.190

Your Answer