This is the code:
$(document).ready(function() {
$('div').html(function(i, html) {
var chars = $.trim(html).split("");
return '<span>' + chars.join('</span><span>') + '</span>';
});
$('div').click(function() {
$('span').each(function() {
$(this).css({
"position": "absolute"
});
$(this).animate({
left: Math.random() * window.outerWidth / 2,
top: Math.random() * window.outerHeight / 2,
});
});
});
});
html,
body {
width: 100%;
height: 100%;
}
div {
font-family: Arial;
font-size: 9vw;
text-transform: uppercase;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>Stack Overflow</div>
If you click the word, the letters should all get a random position. Now: If you click any of the letters, it should look like before. So it should work like a toggle function.