Created
October 21, 2015 07:37
-
-
Save levantoan/4917d32034d5b98b2add to your computer and use it in GitHub Desktop.
Add span to each word
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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