Skip to content

Instantly share code, notes, and snippets.

@levantoan
Created October 21, 2015 07:37
Show Gist options
  • Save levantoan/4917d32034d5b98b2add to your computer and use it in GitHub Desktop.
Save levantoan/4917d32034d5b98b2add to your computer and use it in GitHub Desktop.
Add span to each word
<div class="text">123456</div>
<style>
span{
color: red;
}
</style>
<script>
$('.text').each(function(){
var text = $(this).html().split(''),
len = text.length,
result = [];
for( var i = 0; i < len; i++ ) {
result[i] = '<span>' + text[i] + '</span>';
}
$(this).html(result.join(''));
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment