I am trying to target every space and hyphen within a string and wrap each word with a span. This is what I am trying, obviously is not the best way to achieve this. Any ideas?
$('.whatsOn').each(function() {
var date = $(this).find(".time");
var words = date.text().split(" ");
date.empty();
$.each(words, function(i, v) {
date.append($("<span>").text(v));
});
var wordsSpan = $(this).find(".time span").text().split("-");
$(this).find(".time span").empty();
$.each(words, function(i, v) {
$(this).find(".time span").append($("<span>").text(v));
});
});
<div class="whatsOn">
<dd class="time">14th-29th July</dd>
</div>