What is Join() in jQuery?
What is Join() in jquery? for example:
var newText = $("p").text().split(" ").join("</span> <span>");
Solution 1:
That's not a jQuery function - it's the regular Array.join function.
It converts an array to a string, putting the argument between each element.
Solution 2:
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.