jQuery - Wrap each word of an element in a unique span tag
// Wrap each word in a span.
$('#main-nav a').each(function(){
var text = $(this).text().split(' ');
for( var i = 0, len = text.length; i < len; i++ ) {
text[i] = '<span class="word-' + i + '">' + text[i] + '</span>';
}
$(this).html(text.join(' '));
});
Thanks for your help on the
Thanks for your help on the span tag. Really appreciate it!
Add new comment