James Mitchell
James Mitchell

Reputation: 2467

Having one thing show, after another leaves with jQuery

I made a form in JSFiddle Here: http://jsfiddle.net/LCBradley3k/xqcJS/22/

I made a quick paragraph that just says "Hello World", but it doesn't seem to run after the form hides (once all the user enters correct information).

Here is the Javascipt:

    if (correct) {

        $('#answer').html('Thank You!');
        setTimeout(function(){
    $('.inputs').hide("slide", { direction: "up" }, 1000);
    }, 2000);

        setTimein(function(){
    $('p').show("slide", { direction: "up" }, 1000);
    }, 2000);

 }

You can see that the .inputs hide away, but then after that has been done, I want the setTimein to execute (which shows my test paragraph).

For some reason it doesn't work though. Any reason why?

Upvotes: 1

Views: 134

Answers (2)

Shanimal
Shanimal

Reputation: 11718

HTML

<div id="answer"></div>
<input id="txt" placeholder="Say Something Smart" />
<input type="submit" />

JS

var $answer = $('#answer'),
    $txt = $('#txt'),
    $submit = $('[type=submit]')

$submit.click(function(){
    if(!$txt.val())
        return alert('enter something');
    $answer.html('Thank You!');
    $('input')
        .hide(200)
        .delay(2000)
        .show(200,function(){
            $answer.html('');
            $txt.val('').attr('placeholder','say something else')
        });
});

Codepen

http://codepen.io/anon/pen/uniGy

Upvotes: 1

dmathisen
dmathisen

Reputation: 2342

setTimein doesn't exist. That's not a thing. use setTimeout(function () {...}, 2000)

Upvotes: 0

Related Questions