The following script works fine:

Test Typewriter script

<script src="//" type="text/javascript"></script>

<script type="text/javascript">

var text = "";
var count = 0;
var maxspeed = 200;


function typeit(punch){

function character(start, end, text){
return text.substring(start, end);

function type(){
var random = Math.floor(Math.random() * maxspeed);
setTimeout(type, random);
$('#box').append(character(count, count+1, text));

typeit("This should be output like a typewriter");




<div id="box"></div>

But I'd like to call the typeit function within the body

i.e Use the typeit function by sending the text to the function and have it applied to one or more divs

- and can't figure out how to do it.

Can someone help? - thanks!