Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 903
  • Last Modified:

How to simulate typing using jQuery?

I have a div in html:

Open in new window

I just want the characters to appear one at a time from left to right. I'm using VWD. I thought the easiest way to do it was by usig jQuery but I'm open to suggestions.
1 Solution
Test page :
var s = "1234567890".split("");

var t = setInterval(function() {

    // get the next char from s, remove it from s, and append it to the current content       
    document.getElementById("one_at_time").innerHTML += s.shift();
    // or with jQuery :
    //$("#one_at_time").html( $("#one_at_time").html() + s.shift() );

    // if there's no more char to display stop the timer
    if(s.length==0) clearInterval(t);

}, 1000); // each 1s (1000ms)

Open in new window

<div id="one_at_time"></div>

Open in new window

WhyDidntItWorkAuthor Commented:
It's beautiful. It's a work of art.

Thanks for aching me about the split and shift methods.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now