Solved

How to simulate typing using jQuery?

Posted on 2011-09-11
2
727 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

760 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

24 Experts available now in Live!

Get 1:1 Help Now