I have a paragraph
<div id="unique"> Lorem ipsum dolor</p>
I want to get each word inside this paragraph. I already tried doing
var $texts = $("#unique");
$texts.each(function(i, text){
var str = $(text).text();
console.log(text);
});
But this only gives me the whole text “Lorem ipsum dolor” and not “Lorem”,”ipsum” and “dolor”. Can anyone help me regarding this?
Use the string prototype
.split().