How can i Execute type() function when erase() function completes

Here is a typing animation JS, and here are two function work correctly type() function when we click type button and the erase() function when we click on Erase button.

But now i want to create here a new function that is Erase and Retype means simply i want – When the sentences typed completely and then if we click Erase and Retype button then it should be erase and retype once.

var captionLength = 0;
var caption = '';


$(document).ready(function () {
  captionEl = $('#caption');

  $('#test-typing').click(function () {
    testTypingEffect();
  });

  $('#test-erasing').click(function () {
    testErasingEffect();
  });
});

function testTypingEffect() {
  caption =  $("#qqq").html();
  type();
}

function type() {
  captionEl.html(caption.substr(0, captionLength++));
  if (captionLength < caption.length + 1) {
    setTimeout('type()', 5);
  } else {
    captionLength = 0;
    caption = '';
  }
}

function testErasingEffect() {
  caption = captionEl.html();
  captionLength = caption.length;
  if (captionLength > 0) {
    erase();
  } else {
    $('#caption').html("You didn't write anything to erase, but that's ok!");
    setTimeout('testErasingEffect()', 1000);
  }
}

function erase() {
  captionEl.html(caption.substr(0, captionLength--));
  if (captionLength >= 0) {
    setTimeout('erase()', 5);
  } else {
    captionLength = 0;
    caption = '';
  }
}
<div id="qqq">this is some example sentence which I want to </div>

    
    <input type="button" id="test-typing" value=" Type" />
    <input type="button" id="test-erasing" value="Erase" />  
    <input type="button" id="test-erase-and-retype" value="Erase & Retype" /> 
<br><br>

<span id="caption"></span>


  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

i tried to this help, but i didn’t get success can i know plz what i should to do.

i have already tried this code:

using callback:


  $('#test-erase-and-retype').click(function () {
testErasingEffect(function () {
    testTypingEffect();
});
  });

using when and then condition:


  $('#test-erase-and-retype').click(function () {
  
   $.when(testErasingEffect()).then(testTypingEffect());
      
  });

and this

  $('#test-erase-and-retype').click(function () {

    function firstFunction(){
        testErasingEffect();
    }
    function secondFunction(){
        testTypingEffect();
    }
    
    firstFunction();
});

But all that not working, this only erase text not Re-Type.

Can i know what mistake am making ?

261 thoughts on “How can i Execute type() function when erase() function completes”

  1. I’ve been exploring for a bit for any high-quality articles or weblog posts on this kind of space .
    Exploring in Yahoo I ultimately stumbled upon this site.
    Studying this info So i am happy to convey that I have an incredibly excellent
    uncanny feeling I found out exactly what
    I needed. I most indubitably will make certain to don?t forget this
    website and provides it a look on a relentless basis.

    Also visit my homepage :: Ultra Cut Keto Ingredients

    Reply
  2. I simply could not leave your web site prior to suggesting that I really
    enjoyed the usual information a person supply for your guests?
    Is going to be back continuously in order to investigate cross-check new posts.

    My web-site … telegra.ph

    Reply
  3. Someone essentially help to make critically posts I might state.
    This is the first time I frequented your website page and
    up to now? I amazed with the research you made to create this particular submit
    incredible. Excellent job!

    Also visit my homepage :: khoquet.com

    Reply
  4. Greetings from Idaho! I’m bored to death at work so I decided to check out your blog on my iphone during lunch break.
    I love the info you present here and can’t wait
    to take a look when I get home. I’m shocked at how quick your blog loaded on my mobile
    .. I’m not even using WIFI, just 3G .. Anyhow, wonderful site!

    my web site … librarius.main.jp

    Reply
  5. Pretty part of content. I just stumbled upon your website and in accession capital to say that I acquire in fact enjoyed account your weblog posts.

    Anyway I will be subscribing on your augment and even I achievement you get admission to persistently fast.

    My webpage :: https://spyep.com/

    Reply
  6. I rarely drop comments, however i did a few searching and wound up here
    How can i Execute type() function when erase() function completes
    – JavaScript Help. And I do have some questions for you if
    it’s allright. Is it simply me or does it look as if like
    some of these comments look as if they are written by brain dead people?
    😛 And, if you are posting at other online social sites, I would like to
    keep up with anything fresh you have to post. Would you list of all of all your
    public sites like your twitter feed, Facebook page or linkedin profile?

    my web site :: http://www.mafiamind.com

    Reply
  7. First off I would like to say terrific blog!
    I had a quick question which I’d like to ask if you don’t mind.
    I was curious to find out how you center yourself and clear your thoughts
    prior to writing. I have had a hard time clearing my thoughts
    in getting my ideas out there. I do enjoy writing but it just seems like the first 10 to 15 minutes are generally lost just trying to figure out how to begin. Any ideas or hints?
    Kudos!

    my website :: Keto Redux Reviews

    Reply
  8. Thank you so much for giving everyone an exceptionally superb possiblity to read from this blog.
    It is always so pleasing and also full of amusement for me and my office acquaintances to visit the blog the equivalent of 3 times
    per week to see the newest stuff you have got. And of course, I
    am at all times fulfilled with your unique solutions served by you.
    Some 3 facts on this page are undoubtedly the finest we have had.

    my web blog; Green Earth CBD Gummies Review

    Reply
  9. I know this if off topic but I’m looking into starting my own weblog
    and was wondering what all is required to get setup? I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very web savvy so I’m not 100% certain. Any tips or advice would be greatly appreciated.
    Many thanks

    My blog post; SoloVolt Reviews

    Reply
  10. I seriously love your site.. Great colors & theme.
    Did you make this website yourself? Please reply back as I?m planning to create
    my own site and want to find out where you got
    this from or what the theme is called. Thanks!

    Also visit my web blog; ACV Rx Review

    Reply
  11. I believe that is one of the such a lot
    important info for me. And i am glad studying your article.
    However want to statement on few normal things, The site
    taste is great, the articles is actually great : D. Just right activity,
    cheers

    Reply
  12. Simply to follow up on the up-date of this theme on your site and want to
    let you know just how much I prized the time you
    took to create this helpful post. Within the post, you actually spoke regarding how to really handle this matter with all comfort.
    It would be my pleasure to accumulate some more strategies
    from your web page and come up to offer people what I learned from
    you. Many thanks for your usual excellent effort.

    my web page – windyr17356701.webgarden.cz

    Reply
  13. Hello there! This is my first visit to your blog! We are a team of volunteers and starting a new
    project in a community in the same niche. Your
    blog provided us valuable information to work on. You have
    done a outstanding job!

    Look into my web blog; Keto BHB Plus

    Reply
  14. Thank you, I have just been looking for information approximately
    this subject for a long time and yours is the best I have came upon so far.

    However, what about the bottom line? Are you certain about the supply?

    Visit my web blog :: Arielle

    Reply
  15. We would like to thank you yet again for the
    stunning ideas you offered Jesse when preparing
    a post-graduate research plus, most importantly,
    regarding providing all of the ideas in one blog post. Provided that
    we had been aware of your web-site a year
    ago, we would have been saved the useless measures we were implementing.
    Thank you very much.

    my blog – Erorectin Pills

    Reply
  16. Right here is the perfect web site for anyone
    who wants to understand this topic. You know so much its almost tough to argue with you (not that I actually will need to?HaHa).
    You certainly put a new spin on a subject that has been written about for a long time.
    Excellent stuff, just excellent!

    my page :: Erorectin Ingredients

    Reply
  17. Great ? I should definitely pronounce, impressed with your web site.
    I had no trouble navigating through all tabs and related information ended up being truly simple to
    do to access. I recently found what I hoped for before you know it at all.
    Quite unusual. Is likely to appreciate it for those who add forums or something,
    website theme . a tones way for your customer to communicate.

    Excellent task.

    Also visit my blog post – Slimy Vita

    Reply
  18. I just now wanted to thank you once more for this amazing web
    site you have designed here. It’s full of useful tips for those
    who are definitely interested in this subject, primarily this very
    post. You really are all amazingly sweet in addition to thoughtful of others plus
    reading your blog posts is a good delight to me. And what a
    generous reward! Dan and I will have enjoyment making use of your suggestions in what we should
    instead do in the future. Our checklist is a mile long and tips
    will definitely be put to good use.

    Here is my web site: http://www.fles.hlc.edu.tw/

    Reply
  19. Write more, thats all I have to say. Literally, it
    seems as though you relied on the video to make your point.

    You clearly know what youre talking about, why throw away your intelligence
    on just posting videos to your site when you
    could be giving us something enlightening to read?

    Also visit my blog :: Bio Wellness CBD

    Reply
  20. Hey very nice blog!! Man .. Beautiful .. Wonderful .. I’ll bookmark your website and take
    the feeds also…I am glad to find so many useful information here in the publish, we want develop more techniques on this regard,
    thank you for sharing.

    Here is my website :: Fast Dash Keto

    Reply
  21. Thank you for all of the effort on this web page. My mum take interest in managing investigation and
    it’s really easy to see why. Almost all learn all relating to the dynamic medium you render valuable
    information through your website and even boost contribution from some
    others about this point then our favorite daughter is
    always discovering a great deal. Have fun with the remaining portion of the year.
    Your conducting a superb job.

    Here is my web page Derma Ella

    Reply
  22. Thanks for some other informative blog. Where else may I am getting that type of info written in such a perfect approach?

    I have a mission that I’m just now operating on, and I have been on the look
    out for such information.

    Feel free to visit my blog: http://www.zicd.com

    Reply
  23. Hi there! This post couldn’t be written much better! Looking at this post reminds me of my previous roommate!
    He constantly kept preaching about this. I will send this article to him.
    Fairly certain he’s going to have a great read.

    Thanks for sharing!

    Feel free to visit my webpage: shihan.com.ru

    Reply
  24. Hi there just wanted to give you a quick heads up. The words in your post seem to
    be running off the screen in Ie. I’m not sure if this is
    a formatting issue or something to do with internet browser compatibility
    but I thought I’d post to let you know. The layout look great though!
    Hope you get the issue solved soon. Kudos

    Here is my web page NeoPodz Earbuds

    Reply
  25. hey there and thank you for your information – I have definitely picked up anything new from right
    here. I did however expertise several technical points using this web site, since I experienced to reload the web site lots of times previous to I could get it to load
    properly. I had been wondering if your web hosting is OK?
    Not that I am complaining, but slow loading instances times will sometimes affect your placement in google and can damage your high quality
    score if advertising and marketing with Adwords.
    Anyway I am adding this RSS to my email and can look out for much more of your respective intriguing content.
    Ensure that you update this again soon..

    My web blog True Keto 1800 Ingredients

    Reply
  26. A lot of thanks for each of your labor on this web page.
    Ellie really likes making time for investigation and it’s really obvious why.
    Most people know all about the dynamic method you convey very helpful tactics on your web site and in addition welcome participation from some other
    people about this area of interest while my girl
    is in fact becoming educated a great deal.
    Take pleasure in the rest of the year. You are carrying out a stunning job.[X-N-E-W-L-I-N-MosQiller S Reviews-P-I-N-X]I’m really inspired with
    your writing talents as smartly as with the format for your weblog.
    Is that this a paid theme or did you modify it yourself? Either way keep up the nice quality writing,
    it is uncommon to see a nice blog like this one today.

    Reply
  27. I wish to voice my gratitude for your kind-heartedness for individuals that actually need
    help with this one idea. Your real commitment to passing the solution up and down had become pretty effective and have all the time enabled men and women much like
    me to reach their targets. Your amazing invaluable advice indicates this much to me and much more to my office workers.
    Thanks a lot; from each one of us.

    Feel free to surf to my web site; WifiLift Review

    Reply
  28. Its such as you learn my thoughts! You appear to grasp so much approximately this, such as you wrote
    the guide in it or something. I feel that you simply can do
    with a few percent to pressure the message
    house a little bit, however other than that, this is fantastic blog.
    A great read. I will certainly be back.

    Review my web page; Oracle Leaf Gold CBD

    Reply
  29. Needed to post you that tiny remark to thank you once again for
    your personal great tactics you have contributed above.
    It has been certainly pretty generous with you to make openly
    exactly what many individuals could possibly have sold for an e book to
    help make some money on their own, even more so given that you might have tried it if you ever
    desired. The advice likewise served to become
    a good way to fully grasp other people online have similar dreams the same as my very own to learn a little more
    with reference to this condition. I know there are numerous more pleasant situations ahead
    for those who scan your blog.

    My web-site … forum.m2clasic.ro

    Reply
  30. Hey I know this is off topic but I was wondering if you
    knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and
    was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy
    reading your blog and I look forward to your new updates.

    Feel free to visit my website Semzia Review

    Reply
  31. Good day very nice web site!! Guy .. Beautiful .. Wonderful ..
    I will bookmark your site and take the feeds additionally…I’m happy to seek
    out a lot of helpful info right here in the post, we need work out extra techniques in this regard, thank you
    for sharing.

    Here is my blog post: lose fa

    Reply
  32. Hey I know this is off topic but I was wondering if you knew of any widgets
    I could add to my blog that automatically tweet my newest
    twitter updates. I’ve been looking for a plug-in like this for quite some time and
    was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

    Look into my homepage … Russel

    Reply
  33. Superb site you have here but I was curious if you knew of
    any forums that cover the same topics discussed in this article?
    I’d really like to be a part of community where I can get responses from other
    knowledgeable individuals that share the same interest.

    If you have any recommendations, please let me know.

    Cheers!

    Also visit my web page – carbohydrate timing

    Reply
  34. Just desire to say your article is as amazing. The clearness in your post is simply great and i could assume you’re an expert on this subject.
    Well with your permission let me to grab your RSS feed to keep up to
    date with forthcoming post. Thanks a million and please continue the rewarding work.

    Feel free to surf to my web blog omega 3

    Reply
  35. Hi, i read your blog occasionally and i own a similar one and i was just wondering if
    you get a lot of spam remarks? If so how do you reduce it,
    any plugin or anything you can recommend? I get so much lately it’s driving me mad so any help is very
    much appreciated.

    Also visit my page … http://www.tpspa.net

    Reply
  36. I was just seeking this info for some time. After 6 hours
    of continuous Googleing, finally I got it in your site.
    I wonder what is the lack of Google strategy that don’t rank this type of informative sites in top
    of the list. Normally the top web sites are
    full of garbage.

    Feel free to visit my website … sun screen cream

    Reply