Solved

How to simulate typing using jQuery?

Posted on 2011-09-11
2
731 Views
Last Modified: 2012-08-13
I have a div in html:
<div>1234567890</div>

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.
0
Comment
Question by:WhyDidntItWork
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36520311
Test page : http://jsfiddle.net/CuhCK/
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

0
 

Author Closing Comment

by:WhyDidntItWork
ID: 36520636
It's beautiful. It's a work of art.

Thanks for aching me about the split and shift methods.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now